35 integer,
parameter :: LOG_NONE = 0
36 integer,
parameter :: LOG_ERROR = 1
37 integer,
parameter :: LOG_WARN = 2
38 integer,
parameter :: LOG_INFO = 3
39 integer,
parameter :: LOG_DEBUG = 4
41 integer,
parameter :: STDERR = 0
42 integer,
parameter :: STDOUT = 6
56 integer,
private :: log_ilevel = log_info
58 logical,
private :: log_master
59 #if defined(PGI) || defined(SX)
60 logical,
public :: log_master_nml
62 logical,
private :: log_master_nml
64 logical,
private :: log_opened = .false.
76 integer,
intent(in) :: fid_conf
77 integer,
intent(in),
optional :: fid_log
78 logical,
intent(in),
optional :: master
79 integer,
intent(in),
optional :: fid_nml
80 logical,
intent(in),
optional :: master_nml
82 character(len=5) :: log_level =
'I'
83 character(len=100) :: log_file =
"LOG_"
87 namelist / param_dc_log / &
91 character(len=LOG_LMSG) :: message
98 if (
present(master) ) log_master = master
99 log_master_nml = log_master
100 if (
present(master_nml) ) log_master_nml = master_nml
102 call date_and_time(log_file(4:11), log_file(12:21))
105 if ( fid_conf > 0 )
then
107 read(fid_conf,nml=param_dc_log,iostat=ierr)
109 call log(
'E',
'xxx Not appropriate names in namelist PARAM_DC_LOG. Check!')
113 if (
present(fid_log) )
then
118 file = trim(log_file), &
119 form =
'formatted', &
121 if ( ierr /= 0 )
then
122 call log(
'E',
'xxx File open error! :' // trim(log_file))
128 if (
present(fid_nml) )
then
132 #if defined(PGI) || defined(SX)
133 if ( log_master_nml )
write(
log_fid_nml,nml=param_dc_log)
135 write(message,nml=param_dc_log)
139 select case (trim(log_level))
140 case (
'E',
'e',
'ERROR',
'error')
141 log_ilevel = log_error
142 case (
'W',
'w',
'WARN',
'warn')
143 log_ilevel = log_warn
144 case (
'I',
'i',
'INFO',
'info')
145 log_ilevel = log_info
146 case (
'D',
'd',
'DEBUG',
'debug')
147 log_ilevel = log_debug
149 call log(
'E',
'xxx LOG_LEVEL is invalid. Check!')
157 if ( log_opened )
close(
log_fid)
167 character(len=*),
intent(in) :: type
168 character(len=*),
intent(in) :: message
170 select case (trim(type))
172 if ( log_ilevel >= log_error )
call logput(message)
173 write(stderr,*) trim(message)
176 if ( log_ilevel >= log_warn )
call logput(message)
178 if ( log_ilevel >= log_info )
call logput(message)
180 if ( log_ilevel >= log_debug )
call logput(message)
182 write(stderr,*)
'BUG: wrong log level'
193 character(len=*) :: message
195 if ( log_master )
write(
log_fid, *) trim(message)
198 end subroutine logput
205 character(len=*),
intent(in) :: type
206 character(len=*),
intent(in) :: message
208 select case (trim(type))
210 if ( log_ilevel >= log_error )
call logput_nml(message)
211 write(stderr,*) trim(message)
214 if ( log_ilevel >= log_warn )
call logput_nml(message)
216 if ( log_ilevel >= log_info )
call logput_nml(message)
218 if ( log_ilevel >= log_debug )
call logput_nml(message)
220 write(stderr,*)
'BUG: wrong log level'
228 subroutine logput_nml( &
231 character(len=*) :: message
233 if ( log_master_nml )
write(
log_fid_nml, *) trim(message)
236 end subroutine logput_nml