3 use version_control,
only : swb_version, git_commit_hash_string, &
4 git_branch_string, compile_date, compile_time, &
6 use iso_c_binding,
only : c_bool, c_int
7 use iso_fortran_env,
only : output_unit
26 character (len=:),
allocatable :: spathname
27 character (len=:),
allocatable :: sfileprefix
28 character (len=256) :: sfilename(2)
29 logical (c_bool) :: lisopen(2) = .false._c_bool
30 integer (c_int) :: iunitnum(2) = -999
31 integer (c_int) :: istat(2)
66 logical (c_bool),
parameter ::
true = .
true._c_bool
74 character (len=*),
intent(in) :: sDirName
85 integer (c_int),
intent(in) :: iLogLevel
96 logical (c_bool),
intent(in) :: lEcho
107 integer (c_int),
intent(in),
optional :: iLogLevel
108 character (len=*),
intent(in),
optional :: sFilePrefix
109 logical (c_bool),
intent(in),
optional :: lWrite_SWB_Info
112 integer (c_int) :: iLogLevel_l
113 logical (c_bool) :: lWrite_SWB_Info_l
115 if (
present( lwrite_swb_info) )
then
116 lwrite_swb_info_l = lwrite_swb_info
118 lwrite_swb_info_l = .
true._c_bool
121 if (
present(iloglevel) )
then
122 iloglevel_l = iloglevel
127 if (
present( sfileprefix) )
then
128 this%sFilePrefix = sfileprefix
130 call this%make_prefix()
133 this%iLogLevel = iloglevel_l
134 call this%open( lwrite_swb_info=lwrite_swb_info_l )
143 logical (c_bool),
intent(in),
optional :: lWrite_SWB_Info
146 integer (c_int) :: iIndex
147 character (len=:),
allocatable :: sFilename
148 character (len=:),
allocatable :: sDatetime
149 character (len=12) :: sDescriptor(2) = [
" ",
"_DEBUG " ]
150 logical (c_bool) :: lWrite_SWB_Info_l
152 if (
present( lwrite_swb_info) )
then
153 lwrite_swb_info_l = lwrite_swb_info
155 lwrite_swb_info_l = .
true._c_bool
158 if ( this%iLogLevel /=
log_none )
then
160 do iindex = 1, min(this%iLogLevel, 2)
164 if (.not. this%lIsOpen(iindex) )
then
166 open(newunit=this%iUnitNum(iindex), file=sfilename, iostat=this%iStat(iindex), action=
'WRITE', encoding=
'UTF-8')
167 if (this%iStat(iindex) /= 0)
then
168 write(unit=output_unit, fmt=
"(a)")
"Failed to open logfile "//
'"'//trim(sfilename)//
'".'
172 if (this%iStat(iindex) == 0) this%lIsOpen(iindex) = .
true._c_bool
176 if ( lwrite_swb_info_l )
then
178 write(this%iUnitNum(iindex), fmt=
"(a)")
"# USGS Soil Water Balance Code run log #"
179 write(this%iUnitNum(iindex), fmt=
"(a,/)") repeat(
"-", 80)
180 write(this%iUnitNum(iindex), fmt=
"(a,/)")
"## Model run started on "//sdatetime//
" ##"
181 write(this%iUnitNum(iindex), fmt=
"(a)")
"## SWB version "//swb_version//
" compiled on " &
182 //compilation_timestamp//
" ##"
183 write(this%iUnitNum(iindex), fmt=
"(a,/)")
"Git branch and commit hash: " &
184 //trim( git_branch_string)//
" "//trim(git_commit_hash_string)
190 stop(
"Failed to open file logfile." )
208 integer (c_int) :: iIndex
212 if (this%lIsOpen(iindex) )
then
214 flush ( unit=this%iUnitNum(iindex) )
215 close ( unit=this%iUnitNum(iindex) )
230 integer (c_int) :: iValues(8)
231 character (len=2) :: sHour
232 character (len=2) :: sMinutes
233 character (len=2) :: sSeconds
235 character (len=2) :: sDay
236 character (len=2) :: sMonth
237 character (len=4) :: sYear
239 call date_and_time( values = ivalues )
241 write(shour, fmt=
"(i0.2)") ivalues(
dt_hour )
242 write(sminutes, fmt=
"(i0.2)") ivalues(
dt_minutes )
243 write(sseconds, fmt=
"(i0.2)") ivalues(
dt_seconds )
244 write(smonth, fmt=
"(i0.2)") ivalues(
dt_month )
245 write(sday, fmt=
"(i0.2)") ivalues(
dt_day )
246 write(syear, fmt=
"(i0.4)") ivalues(
dt_year )
248 this%sFilePrefix =
"SWB_LOGFILE__"//syear//smonth//sday//
"_" &
249 //shour//sminutes//sseconds
256 iLinesAfter, iLogLevel, lEcho )
259 character (len=*),
intent(in) :: sMessage
260 integer (c_int),
intent(in),
optional :: iTab
261 integer (c_int),
intent(in),
optional :: iLinesBefore
262 integer (c_int),
intent(in),
optional :: iLinesAfter
263 integer (c_int),
intent(in),
optional :: iLogLevel
264 logical (c_bool),
intent(in),
optional :: lEcho
267 integer (c_int) :: iTab_l
268 integer (c_int) :: iLinesBefore_l
269 integer (c_int) :: iLinesAfter_l
271 if (
present(iloglevel) )
call this%set_loglevel( iloglevel )
272 if (
present(lecho) )
call this%set_echo( lecho )
274 if (
present(itab) )
then
280 if (
present(ilinesbefore) )
then
281 ilinesbefore_l = ilinesbefore
286 if (
present(ilinesafter) )
then
287 ilinesafter_l = ilinesafter
295 itab=itab_l, ilinesbefore=ilinesbefore_l, ilinesafter=ilinesafter_l )
305 itab=itab_l, ilinesbefore=ilinesbefore_l, ilinesafter=ilinesafter_l )
311 itab=itab_l, ilinesbefore=ilinesbefore_l, ilinesafter=ilinesafter_l )
317 itab=itab_l, ilinesbefore=ilinesbefore_l, ilinesafter=ilinesafter_l )
321 itab=itab_l, ilinesbefore=ilinesbefore_l, ilinesafter=ilinesafter_l )
340 character (len=*),
intent(in) :: sMessageText
341 integer (c_int),
intent(in) :: iLU
342 integer (c_int),
intent(in) :: iTab
343 integer (c_int),
intent(in) :: iLinesBefore
344 integer (c_int),
intent(in) :: iLinesAfter
348 character (len=len(sMessageText) ) :: sRecord
349 character (len=256) :: sItem
350 logical (c_bool) :: lFileOpen
351 character (len=12) :: sFmt
352 integer (c_int) :: iIndex
354 inquire (unit=ilu, opened=lfileopen)
356 srecord = trim(smessagetext)
360 if ( ilinesbefore > 0 )
then
361 do iindex=1, ilinesbefore
362 write(unit=ilu, fmt=
"(a,2x)" )
""
369 call split(srecord, sitem)
370 write(sfmt, fmt=
"('(t',i0,' ,a)')") itab
371 if(len_trim(sitem) == 0)
exit
372 write(unit=ilu,fmt=trim(sfmt) ) trim(sitem)//
" "
375 if ( ilinesafter > 0 )
then
376 do iindex=1, ilinesafter
377 write(unit=ilu,fmt=
"(a,2x)" )
""
391 character (len=*),
intent(inout) :: sText1
392 character (len=*),
intent(inout) :: sText2
395 character (len=1) :: sDelimiter
396 integer (c_int) :: iIndex
400 stext1 = adjustl(stext1)
402 iindex = scan( string = stext1, set = sdelimiter )
404 if (iindex == 0)
then
410 stext2 = trim( stext1(1:iindex-1) )
411 stext1 = trim( stext1(iindex + 1:) )
420 character (len=*),
intent(in) :: stext1
421 character (len=len_trim(sText1)+2) :: stext
423 stext =
'"'//trim(stext1)//
'"'
431 character (len=:),
allocatable :: sdatetime
434 integer (c_int) :: ivalues(8)
435 character (len=2) :: shour
436 character (len=2) :: sminutes
437 character (len=2) :: sseconds
439 character (len=2) :: sday
440 character (len=2) :: smonth
441 character (len=4) :: syear
442 character (len=9) :: smonthname
444 character (len=9),
parameter :: months(12) = &
445 [
"January ",
"February ",
"March ",
"April ",
"May ",
"June ",
"July ", &
446 "August ",
"September",
"October ",
"November ",
"December "]
448 call date_and_time( values = ivalues )
450 write(shour, fmt=
"(i0.2)") ivalues(
dt_hour )
451 write(sminutes, fmt=
"(i0.2)") ivalues(
dt_minutes )
452 write(sseconds, fmt=
"(i0.2)") ivalues(
dt_seconds )
453 write(smonth, fmt=
"(i0.2)") ivalues(
dt_month )
454 write(sday, fmt=
"(i0.2)") ivalues(
dt_day )
455 write(syear, fmt=
"(i0.4)") ivalues(
dt_year )
457 smonthname = months( ivalues(
dt_month ) )
459 sdatetime = trim(smonthname)//
" "//sday//
" "//syear//
" "//shour//
":"//sminutes//
":"//sseconds
character(len=len_trim(stext1)+2) function dquote(stext1)
subroutine set_log_level_sub(this, iloglevel)
type(logfile_t), public logs
subroutine write_to_logfiles_sub(this, smessage, itab, ilinesbefore, ilinesafter, iloglevel, lecho)
subroutine open_files_write_access_sub(this, lwrite_swb_info)
subroutine initialize_logfiles_sub(this, iloglevel, sfileprefix, lwrite_swb_info)
character(len=:) function, allocatable make_timestamp()
subroutine make_prefix_sub(this)
subroutine set_output_directory_name_sub(this, sdirname)
subroutine set_screen_echo_sub(this, lecho)
subroutine close_files_sub(this)
logical(c_bool) current_log_echo
subroutine writemultiline(smessagetext, ilu, itab, ilinesbefore, ilinesafter)
Write multiple lines of output to Fortran logical unit.
integer(c_int) current_log_level
character(len=:), allocatable logfile_directory_name
logical(c_bool), parameter true
subroutine split(stext1, stext2)