Changeset 4110 for trunk/LMDZ.COMMON/libf/evolution/display.F90
- Timestamp:
- Mar 9, 2026, 10:29:53 AM (9 days ago)
- File:
-
- 1 edited
-
trunk/LMDZ.COMMON/libf/evolution/display.F90 (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.COMMON/libf/evolution/display.F90
r4076 r4110 25 25 implicit none 26 26 27 ! VARIABLES 28 ! --------- 29 character(128) :: dir = ' ' ! Current directory 30 character(32) :: logname = ' ' ! User name 31 character(32) :: hostname = ' ' ! Machine/station name 27 ! PARAMETERS 28 ! ---------- 29 integer(di), parameter :: LVL_ERR = 0_di ! Only errors 30 integer(di), parameter :: LVL_WRN = 1_di ! Warnings 31 integer(di), parameter :: LVL_NFO = 2_di ! Information (default) 32 integer(di), parameter :: LVL_DBG = 3_di ! Debug 33 character(11), parameter, private :: logfile_name = 'pem_run.log' 34 character(128), protected, private :: curr_dir = ' ' ! Current directory 35 character(32), protected, private :: username = ' ' ! User name 36 character(32), protected, private :: hostname = ' ' ! Machine/station name 37 integer(di), protected, private :: verbosity_lvl = LVL_NFO 38 logical(k4), protected, private :: out2term = .true. ! Flag to output to terminal 39 logical(k4), protected, private :: out2log = .false. ! Flag to output to log file 40 integer(di), protected, private :: logunit = -1_di ! Log file unit 32 41 33 42 contains 34 43 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 44 45 !======================================================================= 46 SUBROUTINE set_display_config(out2term_in,out2log_in,verbosity_lvl_in) 47 !----------------------------------------------------------------------- 48 ! NAME 49 ! set_display_config 50 ! 51 ! DESCRIPTION 52 ! Setter for 'display' configuration parameters. 53 ! 54 ! AUTHORS & DATE 55 ! JB Clement, 03/2026 56 ! 57 ! NOTES 58 ! 59 !----------------------------------------------------------------------- 60 61 ! DECLARATION 62 ! ----------- 63 implicit none 64 65 ! ARGUMENTS 66 ! --------- 67 logical(k4), intent(in) :: out2term_in, out2log_in 68 integer(di), intent(in) :: verbosity_lvl_in 69 70 ! LOCAL VARIABLES 71 ! --------------- 72 integer(di) :: ierr 73 character(100) :: msg 74 75 ! CODE 76 ! ---- 77 out2term = out2term_in 78 out2log = out2log_in 79 verbosity_lvl = verbosity_lvl_in 80 call print_msg('out2term = '//merge('true ','false',out2term),LVL_NFO) 81 call print_msg('out2log = '//merge('true ','false',out2log),LVL_NFO) 82 write(msg,'(a,i1)') 'verbosity_lvl = ',verbosity_lvl 83 call print_msg(msg,LVL_NFO) 84 if (verbosity_lvl < 0 .or. verbosity_lvl > 3) then 85 write(stderr,'(a,i5,a)') '[ERROR] Stopping in "'//__FILE__//'" at line ',__LINE__,'.' 86 write(stderr,'(a)') '[ERROR] Reason: ''verbosity_lvl'' outside admissible range [0,3]!' 87 write(stderr,'(a)') '[ERROR] Houston, we have a problem! Error code = 1' 88 error stop 1 89 end if 90 91 if (out2log) then 92 open(newunit = logunit,file = logfile_name,status = 'replace',form = 'formatted',action = 'write',iostat = ierr) 93 if (ierr /= 0) then 94 write(stderr,'(a,i5,a)') '[ERROR] Stopping in "'//__FILE__//'" at line ',__LINE__,'.' 95 write(stderr,'(a)') '[ERROR] Reason: error opening file "'//logfile_name//'"!' 96 write(stderr,'(a,i3)') '[ERROR] Houston, we have a problem! Error code = ',ierr 97 error stop ierr 98 endif 99 endif 100 if (.not. out2term .and. .not. out2log) write(stdout,*) 'Warning: no output is set!' 101 102 END SUBROUTINE set_display_config 103 !======================================================================= 35 104 36 105 !======================================================================= … … 59 128 character(10) :: time 60 129 character(5) :: zone 130 character(100) :: msg 61 131 integer(di), dimension(8) :: values 62 132 63 133 ! CODE 64 134 ! ---- 65 write(stdout,*) ' * . . + . * . + . . . ' 66 write(stdout,*) ' + _______ ________ ____ ____ * + ' 67 write(stdout,*) ' + . * |_ __ \|_ __ ||_ \ / _| . *' 68 write(stdout,*) ' . . | |__) | | |_ \_| | \/ | * * . ' 69 write(stdout,*) ' . | ___/ | _| _ | |\ /| | . . ' 70 write(stdout,*) '. * * _| |_ _| |__/ | _| |_\/_| |_ * ' 71 write(stdout,*) ' + |_____| |________||_____||_____| + . ' 72 write(stdout,*) ' . * . * . + * . + .' 135 call print_msg(' * . . + . * . + . . . ',LVL_NFO) 136 call print_msg(' + _______ ________ ____ ____ * + ',LVL_NFO) 137 call print_msg(' + . * |_ __ \|_ __ ||_ \ / _| . *',LVL_NFO) 138 call print_msg(' . . | |__) | | |_ \_| | \/ | * * . ',LVL_NFO) 139 call print_msg(' . | ___/ | _| _ | |\ /| | . . ',LVL_NFO) 140 call print_msg('. * * _| |_ _| |__/ | _| |_\/_| |_ * ',LVL_NFO) 141 call print_msg(' + |_____| |________||_____||_____| + . ',LVL_NFO) 142 call print_msg(' . * . * . + * . + .',LVL_NFO) 73 143 74 144 ! Some user info 75 145 call date_and_time(date,time,zone,values) 76 call getcwd( dir)77 call getlog( logname)146 call getcwd(curr_dir) 147 call getlog(username) 78 148 call hostnm(hostname) 79 write(stdout,*) 80 write(stdout,*) '********* PEM information *********' 81 write(stdout,*) '+ User : '//trim(logname) 82 write(stdout,*) '+ Machine : '//trim(hostname) 83 write(stdout,*) '+ Directory: '//trim(dir) 84 write(stdout,'(a,i2,a,i2,a,i4)') ' + Date : ',values(3),'/',values(2),'/',values(1) 85 write(stdout,'(a,i2,a,i2,a,i2,a)') ' + Time : ',values(5),':',values(6),':',values(7) 86 write(stdout,*) 87 write(stdout,*) '********* Initialization *********' 149 call print_msg('',LVL_NFO) 150 call print_msg('********* PEM information *********',LVL_NFO) 151 call print_msg('+ User : '//trim(username),LVL_NFO) 152 call print_msg('+ Machine : '//trim(hostname),LVL_NFO) 153 call print_msg('+ Directory: '//trim(curr_dir),LVL_NFO) 154 write(msg,'(a,i2,a,i2,a,i4)') '+ Date : ',values(3),'/',values(2),'/',values(1) 155 call print_msg(msg,LVL_NFO) 156 write(msg,'(a,i2,a,i2,a,i2,a)') '+ Time : ',values(5),':',values(6),':',values(7) 157 call print_msg(msg,LVL_NFO) 158 call print_msg('',LVL_NFO) 159 call print_msg('********* Initialization *********',LVL_NFO) 88 160 89 161 END SUBROUTINE print_ini … … 105 177 ! 106 178 !----------------------------------------------------------------------- 107 108 ! DEPENDENCIES109 ! ------------110 use utility, only: format_duration, int2str111 179 112 180 ! DECLARATION … … 119 187 integer(di), intent(in) :: i_pem_run 120 188 121 ! CODE 122 ! ---- 123 write(stdout,*) 124 write(stdout,*) '****** PEM final information *******' 125 write(*,'(a,f16.4,a)') ' + The run PEM #'//int2str(i_pem_run)//' achieved ', n_yr_run, ' Planetary years, completed in '//format_duration(dur_secs)//'.' 126 write(*,'(a,f16.4,a,f16.4,a)') ' + The workflow has achieved ', n_yr_sim, ' Planetary years =', n_yr_sim*r_plnt2earth_yr, ' Earth years.' 127 write(*,'(a,f16.4,a)') ' + The reached date is now ', (pem_ini_date + n_yr_sim)*r_plnt2earth_yr, ' Earth years.' 128 write(*,*) '+ PEM: so far, so good!' 129 write(stdout,*) '************************************' 189 ! LOCAL VARIABLES 190 ! --------------- 191 character(100) :: msg 192 193 ! CODE 194 ! ---- 195 call print_msg('',LVL_NFO) 196 call print_msg('****** PEM final information *******',LVL_NFO) 197 write(msg,'(a,i0,a,f16.4,a)') ' + The run PEM #',i_pem_run,' achieved ', n_yr_run, ' Planetary years, completed in '//format_duration(dur_secs)//'.' 198 call print_msg(msg,LVL_NFO) 199 write(msg,'(a,f16.4,a,f16.4,a)') ' + The workflow has achieved ', n_yr_sim, ' Planetary years =', n_yr_sim*r_plnt2earth_yr, ' Earth years.' 200 call print_msg(msg,LVL_NFO) 201 write(msg,'(a,f16.4,a)') ' + The reached date is now ', (pem_ini_date + n_yr_sim)*r_plnt2earth_yr, ' Earth years.' 202 call print_msg(msg,LVL_NFO) 203 call print_msg('+ PEM: so far, so good!',LVL_NFO) 204 call print_msg('************************************',LVL_NFO) 130 205 call but_why(n_yr_run) 131 206 207 ! Close log file 208 if (out2log) close(logunit) 209 132 210 END SUBROUTINE print_end 133 211 !======================================================================= 134 212 135 213 !======================================================================= 136 SUBROUTINE print_msg(message, frmt)214 SUBROUTINE print_msg(message,lvl) 137 215 !----------------------------------------------------------------------- 138 216 ! NAME … … 140 218 ! 141 219 ! DESCRIPTION 142 ! Print a simple message (string).143 ! 144 ! AUTHORS & DATE 145 ! JB Clement, 0 2/2026220 ! Print a message (string) based on verbosity. 221 ! 222 ! AUTHORS & DATE 223 ! JB Clement, 03/2026 146 224 ! 147 225 ! NOTES … … 155 233 ! ARGUMENTS 156 234 ! --------- 157 character(*), intent(in) :: message 158 character(*), intent(in), optional :: frmt 159 160 ! CODE 161 ! ---- 162 if (present(frmt)) then 163 write(stdout,frmt) message 164 else 165 write(stdout,*) message 235 character(*), intent(in) :: message 236 integer(di), intent(in) :: lvl 237 238 ! LOCAL VARIABLES 239 ! --------------- 240 character(:), allocatable :: prefix 241 integer(di) :: outunit 242 243 ! CODE 244 ! ---- 245 ! Filter based on verbosity 246 if (lvl > verbosity_lvl) return 247 248 ! Prefix selection 249 select case (lvl) 250 case (LVL_ERR) 251 prefix = '[ERROR] ' 252 case (LVL_WRN) 253 prefix = '[WARNING] ' 254 case (LVL_NFO) 255 prefix = '' 256 case (LVL_DBG) 257 prefix = '[DEBUGGING] ' 258 case default 259 write(stderr,'(a,i5,a)') '[ERROR] Stopping in "'//__FILE__//'" at line ',__LINE__,'.' 260 write(stderr,'(a)') '[ERROR] Reason: unknown verbosity level for the message!' 261 write(stderr,'(a)') '[ERROR] Houston, we have a problem! Error code = 1' 262 error stop 1 263 end select 264 265 ! Terminal output 266 if (out2term) then 267 if (lvl == LVL_ERR) then 268 outunit = stderr 269 else 270 outunit = stdout 271 end if 272 write(outunit,'(a)') prefix//message 166 273 end if 167 274 275 ! Log file output 276 if (out2log) write(logunit,'(a)') prefix//message 277 168 278 END SUBROUTINE print_msg 169 279 !======================================================================= 170 280 171 281 !======================================================================= 172 SUBROUTINE print_err(message,frmt)173 !----------------------------------------------------------------------- 174 ! NAME 175 ! print_err176 ! 177 ! DESCRIPTION 178 ! Print a simple message (string).179 ! 180 ! AUTHORS & DATE 181 ! JB Clement, 0 2/2026282 FUNCTION format_duration(secs) RESULT(str) 283 !----------------------------------------------------------------------- 284 ! NAME 285 ! format_duration 286 ! 287 ! DESCRIPTION 288 ! Converts a duration in seconds into a compact Xd HH:MM:SS format. 289 ! 290 ! AUTHORS & DATE 291 ! JB Clement, 01/2026 182 292 ! 183 293 ! NOTES … … 191 301 ! ARGUMENTS 192 302 ! --------- 193 character(*), intent(in) :: message 194 character(*), intent(in), optional :: frmt 195 196 ! CODE 197 ! ---- 198 if (present(frmt)) then 199 write(stderr,frmt) message 303 real(dp), intent(in) :: secs 304 305 ! LOCAL VARIABLES 306 ! --------------- 307 integer(di) :: days, hours, minutes, seconds 308 character(:), allocatable :: str 309 character(32) :: tmp ! Work buffer 310 311 ! CODE 312 ! ---- 313 days = int(secs/86400._dp,di) 314 hours = int(mod(secs,86400._dp)/3600._dp,di) 315 minutes = int(mod(secs,3600._dp)/60._dp,di) 316 seconds = int(mod(secs,60._dp),di) 317 318 if (days > 0_li) then 319 write(tmp,'(i0,"d ",i2.2,":",i2.2,":",i2.2)') days, hours, minutes, seconds 200 320 else 201 write(stderr,*) message321 write(tmp,'(i2.2,":",i2.2,":",i2.2)') hours, minutes, seconds 202 322 end if 203 323 204 END SUBROUTINE print_err 324 str = trim(adjustl(tmp)) 325 326 END FUNCTION format_duration 205 327 !======================================================================= 206 328 … … 342 464 343 465 if (gottacatch_emall_()) then 344 write(stdout,*)466 call print_msg('',LVL_NFO) 345 467 if (abs(n_yr_run - first_gen) < minieps) then 346 468 do i = 1,size(surprise) 347 write(stdout,*) trim(surprise(i))469 call print_msg(trim(surprise(i)),LVL_NFO) 348 470 end do 349 write(stdout,*) ' '471 call print_msg('',LVL_NFO) 350 472 do i = 1,size(exeggutor,1) 351 write(stdout,*) trim(confusion(exeggutor(i,:)))473 call print_msg(trim(confusion(exeggutor(i,:))),LVL_NFO) 352 474 end do 353 475 else 354 476 do i = 1,size(why_not) 355 write(stdout,*) trim(why_not(i))477 call print_msg(trim(why_not(i)),LVL_NFO) 356 478 end do 357 479 end if … … 396 518 flag = trim(why_yes) == 'yes' 397 519 if (.not. flag) then 398 write(stdout,*)399 write(stdout,*) trim(confusion(who))520 call print_msg('',LVL_NFO) 521 call print_msg(trim(confusion(who)),LVL_NFO) 400 522 end if 401 523 end if
Note: See TracChangeset
for help on using the changeset viewer.
