PB3D
[2.45]
Ideal linear high-n MHD stability in 3-D
|
Go to the documentation of this file.
68 call write_formatted(
' PB3D Copyright (C) 2019 Toon Weyens',&
70 call write_formatted(
' This program comes with ABSOLUTELY NO &
72 call write_formatted(
' This is free software, and you are welcome &
73 &to redistribute it',
'italic')
74 call write_formatted(
' under certain conditions; See LICENSE for &
76 call write_formatted(
'',
'italic')
78 call write_formatted(
' Simulation started on '//get_date()//
', at '&
80 call write_formatted(
' '//
prog_name//
' version: '//&
83 call write_formatted(
' debug version',
'italic')
85 call write_formatted(
' release version',
'italic')
88 call write_formatted(
' 1 MPI process',
'italic')
91 &
' MPI processes',
'italic')
93 write(*,*,iostat=istat)
''
105 write(*,*,iostat=istat)
''
106 call write_formatted(
' Simulation finished on '//get_date()//&
122 call writo(
'Tried to start timer, but was already running',&
136 deltat = deltat+t2-t1
143 call writo(
'Tried to stop timer, but was already stopped',&
153 character(len=max_str_ln) :: begin_str, end_str
154 integer :: time_in_units(4)
155 integer :: total_time
156 character(len=6) :: time_units(4) = [
'day ',
'hour ',
'minute',&
163 begin_str =
'(this took'
164 if (deltat.lt.1)
then
165 end_str =
' less than 1 second)'
168 total_time = floor(deltat)
169 time_in_units(1) = total_time/(60*60*24)
170 total_time = mod(total_time,60*60*24)
171 time_in_units(2) = total_time/(60*60)
172 total_time = mod(total_time,60*60)
173 time_in_units(3) = total_time/(60)
174 total_time = mod(total_time,60)
175 time_in_units(4) = total_time
180 if (time_in_units(id).gt.0)
then
181 if (trim(end_str).ne.
'') end_str = trim(end_str)//
','
182 end_str = trim(end_str)//
' '//&
183 &trim(
i2str(time_in_units(id)))//
' '//&
184 &trim(time_units(id))
185 if (time_in_units(id).gt.1) end_str = trim(end_str)//
's'
188 end_str = trim(end_str)//
')'
190 call writo(trim(begin_str) // trim(end_str))
199 function get_date()
result(now)
200 #if (lwith_intel && !lwith_gnu)
204 character(len=10) :: now
211 write (now,
'(i2.2,"/",i2.2,"/",i4.4)') today(2), today(1), today(3)
212 end function get_date
219 character(len=8) :: time
226 write (time,
'(i2.2,":",i2.2,":",i2.2)') now
237 character(len=*),
intent(in) :: err_msg
238 character(len=*),
intent(in) :: routine_name
240 if (trim(err_msg).eq.
'')
then
242 call writo(
'>> calling routine: '//trim(routine_name)//
' of rank '&
245 call writo(
'ERROR in '//trim(routine_name)//
': '//trim(err_msg),&
246 &persistent=.true.,error=.true.)
257 if (
lvl+inc.lt.1)
then
259 call writo(
'cannot go below lowest level',warning=.true.)
274 subroutine writo(input_str,persistent,error,warning,alert)
283 character(len=*),
intent(in) :: input_str
284 logical,
intent(in),
optional :: persistent
285 logical,
intent(in),
optional :: error
286 logical,
intent(in),
optional :: warning
287 logical,
intent(in),
optional :: alert
291 character(len=0),
parameter :: bright_str =
""
292 character(len=max_str_ln) :: output_str
293 character(len=max_str_ln) :: time_str
294 character(len=max_str_ln) :: header_str
295 character(len=max_str_ln) :: input_str_loc
296 character(len=max_str_ln),
allocatable :: temp_output_loc(:)
297 integer :: id, i_part
298 integer :: max_len_part, num_parts, st_part, en_part
301 logical :: warning_loc
306 integer(kind=8) :: clock
310 if (no_output)
return
314 if (rank.eq.0) ignore = .false.
315 if (
present(persistent)) ignore = .not.persistent
317 if (
present(error)) error_loc = error
318 warning_loc = .false.
319 if (
present(warning)) warning_loc = warning
321 if (
present(alert)) alert_loc = alert
324 input_str_loc = input_str
327 if (warning_loc) input_str_loc =
'WARNING: '//trim(input_str_loc)
339 input_str_loc = trim(input_str_loc)//
' - ['//&
341 &trim(
i2str(mem_usage))//
'kB]'
344 call system_clock(clock)
350 &position=
'append',iostat=istat)
355 &max_tot_mem*1000, max_x_mem*1000
362 if (.not.ignore)
then
368 num_parts = (len(trim(input_str_loc))-1)/(max_len_part) + 1
369 do i_part = 1, num_parts
371 st_part = (i_part-1)*max_len_part+1
372 if (i_part.lt.num_parts)
then
373 en_part = i_part*max_len_part
375 en_part = len(trim(input_str_loc))
377 output_str = input_str_loc(st_part:en_part)
378 call format_str(
lvl,output_str)
379 call get_time_str(time_str)
383 do id = 1, len(trim(output_str)) + len(trim(time_str)) + 1 - &
385 header_str = trim(header_str) //
'-'
387 header_str =
' '//trim(header_str)
399 temp_output(1:
size(temp_output_loc)) = temp_output_loc
400 temp_output(
size(temp_output_loc)+1) = trim(header_str)
401 temp_output(
size(temp_output_loc)+2) = trim(time_str)//&
402 &
' '//trim(output_str)
403 temp_output(
size(temp_output_loc)+3) = trim(header_str)
406 temp_output(1:
size(temp_output_loc)) = temp_output_loc
407 temp_output(
size(temp_output_loc)+1) = trim(time_str)//&
412 deallocate(temp_output_loc)
414 if (output_i.ne.0)
then
415 if (
lvl.eq.1)
write(output_i,
"(1X,A)",iostat=istat) &
417 write(output_i,
"(1X,A)",iostat=istat) &
418 &trim(time_str)//
' '//trim(output_str)
419 if (
lvl.eq.1)
write(output_i,
"(1X,A)",iostat=istat) &
426 call write_formatted(
' '//trim(time_str)//
' ',&
427 &
'background_red',trim(output_str),
'italic underline')
428 else if (warning_loc .or. alert_loc)
then
429 call write_formatted(
' '//trim(time_str)//
' ',&
430 &
'background_cyan',trim(output_str),
'italic underline')
431 else if (
lvl.eq.1)
then
432 call write_formatted(
' '//trim(header_str),&
433 &bright_str//
'green')
434 call write_formatted(
' '//trim(time_str)//
' ',
'',&
435 &trim(output_str),bright_str//
'green')
436 call write_formatted(
' '//trim(header_str),&
437 &bright_str//
'green')
438 else if (
lvl.eq.2)
then
439 call write_formatted(
' '//trim(time_str)//
' ',
'',&
440 &trim(output_str),bright_str//
'blue')
442 write(*,
"(1X,A)",iostat=istat) &
443 &trim(time_str)//
' '//trim(output_str)
450 subroutine format_str(lvl,str)
452 integer,
intent(in) ::
lvl
453 character(len=*),
intent(inout) :: str
461 end subroutine format_str
465 subroutine get_time_str(time_str)
467 character(len=*),
intent(inout) :: time_str
470 end subroutine get_time_str
476 real(
dp),
intent(in) :: arr(:,:)
488 real(
dp),
intent(in) :: arr(:)
492 character(len=2*max_str_ln) :: output_str
493 character(len=14) :: var_str
504 do while(.not.str_full .and. id.le.
size(arr))
506 n_free = len(output_str) - len(trim(output_str))
508 if (n_free.ge.2*vlen+6)
then
510 else if (2*vlen+2.le.n_free .and. n_free.lt.2*vlen+6 .and. &
511 &id+1.ge.
size(arr))
then
513 else if (vlen+6.le.n_free .and. n_free.lt.2*vlen+6)
then
514 if (id.ge.
size(arr))
then
519 else if (vlen+2.le.n_free .and. n_free.lt.vlen+6 .and. &
520 &id.eq.
size(arr))
then
523 call writo(
'not enough room to display variable. Something &
524 &went wrong',warning=.true.)
530 write (var_str,
'(ES9.2)') arr(
size(arr))
531 var_str =
' ... ' // trim(var_str)
533 write (var_str,
'(ES9.2)') arr(id)
534 var_str =
' ' // trim(var_str)
536 output_str = trim(output_str) // trim(var_str)
540 output_str = trim(output_str) //
' |'
541 write(*,
'(1X,A)',iostat=istat) output_str
555 #if ( lwith_intel && !lwith_gnu)
560 character(len=200):: filename=
' '
561 character(len=80) :: line
562 character(len=8) :: pid_char=
' '
572 write(pid_char,
'(I8)') pid
575 filename=
'/proc/'//trim(adjustl(pid_char))//
'/status'
578 inquire (file=filename,exist=exists)
579 if (.not.exists)
return
582 open(unit=
mem_usage_i-1,file=filename,action=
'read',iostat=istat)
583 if (istat.ne.0)
return
586 if (istat.ne.0)
return
587 if (line(1:6).eq.
'VmRSS:')
then
588 read (line(7:),*) mem
integer, parameter, public dp
double precision
subroutine, public print_ar_1(arr)
Print an array of dimension 1 on the screen.
Numerical variables used by most other modules.
integer, parameter, public max_str_ln
maximum length of strings
subroutine, public passed_time()
Display the time that has passed between t1 and t2.
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
subroutine, public print_ar_2(arr)
Print an array of dimension 2 on the screen.
subroutine, public start_time()
Start a timer.
integer function, public get_mem_usage()
Returns the memory usage in kilobytes.
integer, public n_procs
nr. of MPI processes
subroutine, public stop_time()
Stop a timer.
logical, public debug_version
debug version used
integer, public lvl
determines the indenting. higher lvl = more indenting
elemental character(len=max_str_ln) function, public r2strt(k)
Convert a real (double) to string.
character(len=4), public prog_name
name of program, used for info
character(len=10), public time_sep
defines the length of time part of output
logical, public print_mem_usage
print memory usage is printed
integer, parameter, public mem_usage_i
file number of memory usage file
integer, public mem_usage_count
counter for memory usage output
character(len=2), public lvl_sep
characters that separate different levels of output
logical, public no_output
no output shown
character(len=max_str_ln), dimension(:), allocatable, public temp_output
temporary output, before output file is opened
subroutine, public writo(input_str, persistent, error, warning, alert)
Write output to file identified by output_i.
Numerical utilities related to giving output.
character(len=9), parameter, public mem_usage_name
name of memory usage file
character(len=8) function get_clock()
Returns the time.
subroutine, public print_goodbye()
Prints last messag.
integer(kind=8), public time_start
start time of simulation
subroutine, public lvl_ud(inc)
Increases/decreases lvl of output.
real(dp), parameter, public prog_version
version number
subroutine, public print_err_msg(err_msg, routine_name)
Prints an error message that is either user-provided, or the name of the calling routine.
subroutine, public init_time()
Intialize the time passed to 0.
subroutine, public init_output()
Initialize the variables for the module.
integer, public rank
MPI rank.
integer, parameter, public output_i
file number of output file
real(dp), public max_tot_mem
maximum total memory for all processes [MB]
logical, public temp_output_active
true if temporary output is to be written in temp_output
real(dp), public max_x_mem
maximum memory for perturbation calculations for all processes [MB]
subroutine, public print_hello()
Prints first message.