56 integer,
parameter,
public :: iunit_out = 8
57 integer,
parameter,
public :: iunit_err = 9
58 character(len=MAX_PATH_LEN) :: work_dir
59 character(len=MAX_PATH_LEN) :: current_working_dir
60 integer(int64),
save :: io_open_count
61 integer(int64),
save :: io_close_count
70 logical,
optional,
intent(in) :: defaults
72 character(len=MAX_PATH_LEN) :: filename
78 call get_environment_variable(
"PWD", current_working_dir, status=status)
80 write(*,
'("ERROR: could not determine current working directory!")')
87 if (
present(defaults))
then
92 work_dir = current_working_dir
110 if (trim(filename) /=
'-')
then
112 open(stdout, file=filename, status=
'unknown')
127 if (trim(filename) /=
'-')
then
129 open(stderr, file=filename, status=
'unknown')
161 if (work_dir /=
'.')
call loct_mkdir(trim(work_dir))
163 if (
debug%info .or.
debug%interaction_graph .or.
debug%propagation_graph)
then
167 if (
debug%trace_file)
then
179 if (stderr /= 0)
call io_close(stderr)
180 if (stdin /= 5)
call io_close(stdin)
181 if (stdout /= 6)
call io_close(stdout)
190 character(len=MAX_PATH_LEN) function io_workdir()
result (wpath)
192 integer :: len_work_dir
193 character :: first_char
195 len_work_dir = len_trim(work_dir)
196 first_char = work_dir(1:1)
198 select case (first_char)
203 if (len_work_dir>1)
then
205 wpath = trim(current_working_dir) // trim(work_dir(2:len_work_dir))
207 wpath = current_working_dir
211 wpath = trim(current_working_dir) //
"/" // trim(work_dir)
222 character(len=MAX_PATH_LEN) function io_workpath(path, namespace)
result(wpath)
223 character(len=*),
intent(in) :: path
224 type(
namespace_t),
optional,
intent(in) :: namespace
226 logical :: absolute_path
230 absolute_path = .false.
231 if (len_trim(path) > 0)
then
232 absolute_path = path(1:1) ==
'/'
236 total_len = len_trim(path)
237 if (.not. absolute_path)
then
238 total_len = total_len + len_trim(work_dir) + 1
239 if (
present(namespace))
then
240 if (namespace%len() > 0) total_len = total_len + namespace%len() + 1
244 write(stderr,
"(A,I5)")
"Path is longer than the maximum path length of ",
max_path_len
245 write(stderr,
"(A)") path
249 if (absolute_path)
then
253 wpath = trim(work_dir)
254 if (
present(namespace))
then
256 if (namespace%len() > 0) wpath = trim(wpath) +
"/" + trim(namespace%get(
'/'))
258 wpath = trim(wpath) +
"/" + trim(path)
265 subroutine io_mkdir(fname, namespace, parents)
266 character(len=*),
intent(in) :: fname
267 type(
namespace_t),
optional,
intent(in) :: namespace
268 logical,
optional,
intent(in) :: parents
271 integer :: last_slash, pos, length
274 if (
present(parents)) parents_ = parents
276 if (.not. parents_)
then
280 last_slash = max(index(fname,
"/", .
true.), len_trim(fname))
282 length = index(fname,
'/') - 1
283 do while (pos < last_slash)
285 pos = pos + length + 1
286 length = index(fname(pos:),
"/") - 1
287 if (length < 1) length = len_trim(fname(pos:))
296 subroutine io_rm(fname, namespace)
297 character(len=*),
intent(in) :: fname
298 type(
namespace_t),
optional,
intent(in) :: namespace
306 integer function io_open(file, namespace, action, status, form, position, die, recl, grp)
result(iunit)
307 character(len=*),
intent(in) :: file, action
308 type(
namespace_t),
intent(in),
optional :: namespace
309 character(len=*),
intent(in),
optional :: status, form, position
310 logical,
intent(in),
optional :: die
311 integer,
intent(in),
optional :: recl
312 type(
mpi_grp_t),
intent(in),
optional :: grp
314 character(len=20) :: status_, form_, position_
315 character(len=MAX_PATH_LEN) :: file_
318 character(len=100) :: io_emsg
321 if (
present(grp))
then
330 if (grp_%is_root())
then
333 if (
present(status)) status_ = status
335 if (
present(form)) form_ = form
337 if (
present(position)) position_ = position
343 if (
present(recl))
then
344 open(newunit=iunit, file=trim(file_), status=trim(status_), form=trim(form_), &
345 recl=recl, action=trim(action), position=trim(position_), iostat=iostat, iomsg=io_emsg)
347 open(newunit=iunit, file=trim(file_), status=trim(status_), form=trim(form_), &
348 action=trim(action), position=trim(position_), iostat=iostat, iomsg=io_emsg)
351 io_open_count = io_open_count + 1
353 if (iostat /= 0)
then
356 write(stderr,
'(a,a)')
'*** IO Error: ', trim(io_emsg)
363 if (grp_%size > 1)
then
364 call grp_%bcast(iunit, 1, mpi_integer, 0)
372 integer,
intent(inout) :: iunit
373 type(
mpi_grp_t),
intent(in),
optional :: grp
377 if (
present(grp))
then
385 if (grp_%is_root())
then
387 io_close_count = io_close_count + 1
396 integer,
intent(in) :: ounit
397 character(len=*),
intent(in) :: filename
399 integer :: iunit, err
400 character(len=80) :: line
404 open(newunit=iunit, file=filename, iostat=err, action=
'read', status=
'old')
407 read(iunit, fmt=
'(a80)', iostat=err) line
409 write(ounit,
'(a)') trim(line)
423 character(len = *),
intent(in) :: path
426 i = index(path,
".", back = .
true.)
427 j = index(path(i+1:),
"/")
428 if (i == 0 .or. j /= 0)
then
444 if (
io_file_exists(
'enable_debug_mode', msg=
'Enabling DebugMode'))
then
450 call loct_rm(
'enable_debug_mode')
455 if (
io_file_exists(
'disable_debug_mode', msg=
'Disabling DebugMode'))
then
458 call loct_rm(
'disable_debug_mode')
469 logical function io_file_exists(filename, msg)
result(file_exists)
470 character(len=*),
intent(in) :: filename
471 character(len=*),
optional,
intent(in) :: msg
473 file_exists = .false.
474 inquire(file=trim(filename), exist=file_exists)
475 if (file_exists .and.
present(msg))
then
476 write(stderr,
'(a)') trim(msg)
484 character(len=*),
intent(in) :: dir
485 type(
namespace_t),
optional,
intent(in) :: namespace
492 subroutine iopar_read(grp, iunit, lines, n_lines, ierr)
494 integer,
intent(in) :: iunit
495 character(len=*),
intent(out) :: lines(:)
496 integer,
intent(in) :: n_lines
497 integer,
intent(out) :: ierr
501 assert(n_lines <=
size(lines))
503 if (grp%is_root())
then
505 read(iunit,
'(a)', iostat=ierr) lines(il)
510 call grp%bcast(ierr, 1, mpi_integer, 0)
511 call grp%bcast(lines(1), len(lines(1))*n_lines, mpi_character, 0)
518 integer,
intent(in) :: iunit
520 if (grp%is_root())
then
530 integer,
intent(in) :: iunit
531 character(len=*),
intent(in) :: line
532 integer,
intent(out) :: ierr
534 character(len=80) :: read_line
536 if (grp%is_root())
then
539 read(iunit,
'(a)', iostat=ierr) read_line
540 if (ierr /= 0 .or. trim(line) == trim(read_line))
exit
544 call grp%bcast(ierr, 1, mpi_integer, 0)
551 integer,
intent(in) :: iunit
553 character(len=1) :: a
567 count = io_open_count
594 integer,
intent(in) :: iio
596 integer :: open_count
598 open_count = int(iio/100)
subroutine, public debug_enable(this)
type(debug_t), save, public debug
subroutine, public debug_disable(this)
subroutine, public debug_delete_trace()
integer, public no_sub_stack
integer, parameter, public max_path_len
Public types, variables and procedures.
character(len=8) function, public io_get_extension(path)
Given a path, it returns the extension (if it exists) of the file (that is, the part of the name that...
integer(int64), save io_open_count
subroutine, public io_init(defaults)
If the argument defaults is present and set to true, then the routine will not try to read anything f...
subroutine, public io_close(iunit, grp)
subroutine, public io_skip_header(iunit)
subroutine, public io_incr_counters(iio)
subroutine, public io_incr_close_count()
subroutine, public io_end()
subroutine, public iopar_read(grp, iunit, lines, n_lines, ierr)
integer(int64) pure function, public io_get_close_count()
logical function, public io_file_exists(filename, msg)
Returns true if a file with name 'filename' exists and issues a reminder.
character(len=max_path_len) function, public io_workpath(path, namespace)
construct path name from given name and namespace
subroutine, public io_incr_open_count()
subroutine, public iopar_backspace(grp, iunit)
integer(int64), save io_close_count
subroutine, public io_debug_on_the_fly(namespace)
check if debug mode should be enabled or disabled on the fly
subroutine, public io_rm(fname, namespace)
character(len=max_path_len) function, public io_workdir()
construct working directory
subroutine, public io_mkdir(fname, namespace, parents)
logical function, public io_dir_exists(dir, namespace)
Returns true if a dir with name 'dir' exists.
subroutine, public iopar_find_line(grp, iunit, line, ierr)
integer(int64) pure function, public io_get_open_count()
subroutine, public io_dump_file(ounit, filename)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
System information (time, memory, sysname)
subroutine, public loct_rm(name)
subroutine, public loct_mkdir(name)
logical, public show_progress_bar
Define which routines can be seen from the outside.
logical function, public loct_dir_exists(dirname)
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
type(mpi_grp_t), public mpi_world
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
type(namespace_t), public global_namespace
This is defined even when running serial.