55 integer,
parameter,
public :: iunit_out = 8
56 integer,
parameter,
public :: iunit_err = 9
57 character(len=MAX_PATH_LEN) :: work_dir
58 integer(int64),
save :: io_open_count
59 integer(int64),
save :: io_close_count
68 logical,
optional,
intent(in) :: defaults
70 character(len=MAX_PATH_LEN) :: filename
77 if (
present(defaults))
then
100 if (trim(filename) /=
'-')
then
102 open(stdout, file=filename, status=
'unknown')
116 if (trim(filename) /=
'-')
then
118 open(stderr, file=filename, status=
'unknown')
156 if (
debug%trace_file)
then
168 if (stderr /= 0)
call io_close(stderr)
169 if (stdin /= 5)
call io_close(stdin)
170 if (stdout /= 6)
call io_close(stdout)
176 character(len=MAX_PATH_LEN) function io_workpath(path, namespace)
result(wpath)
177 character(len=*),
intent(in) :: path
178 type(
namespace_t),
optional,
intent(in) :: namespace
180 logical :: absolute_path
184 absolute_path = .false.
185 if (len_trim(path) > 0)
then
186 absolute_path = path(1:1) ==
'/'
190 total_len = len_trim(path)
191 if (.not. absolute_path)
then
192 total_len = total_len + len_trim(work_dir) + 1
193 if (
present(namespace))
then
194 if (namespace%len() > 0) total_len = total_len + namespace%len() + 1
198 write(stderr,
"(A,I5)")
"Path is longer than the maximum path length of ",
max_path_len
201 if (absolute_path)
then
205 wpath = trim(work_dir)
206 if (
present(namespace))
then
208 if (namespace%len() > 0) wpath = trim(wpath) +
"/" + trim(namespace%get(
'/'))
210 wpath = trim(wpath) +
"/" + trim(path)
217 subroutine io_mkdir(fname, namespace, parents)
218 character(len=*),
intent(in) :: fname
219 type(
namespace_t),
optional,
intent(in) :: namespace
220 logical,
optional,
intent(in) :: parents
223 integer :: last_slash, pos, length
226 if (
present(parents)) parents_ = parents
228 if (.not. parents_)
then
232 last_slash = max(index(fname,
"/", .
true.), len_trim(fname))
234 length = index(fname,
'/') - 1
235 do while (pos < last_slash)
237 pos = pos + length + 1
238 length = index(fname(pos:),
"/") - 1
239 if (length < 1) length = len_trim(fname(pos:))
248 subroutine io_rm(fname, namespace)
249 character(len=*),
intent(in) :: fname
250 type(
namespace_t),
optional,
intent(in) :: namespace
258 integer function io_open(file, namespace, action, status, form, position, die, recl, grp)
result(iunit)
259 character(len=*),
intent(in) :: file, action
260 type(
namespace_t),
intent(in),
optional :: namespace
261 character(len=*),
intent(in),
optional :: status, form, position
262 logical,
intent(in),
optional :: die
263 integer,
intent(in),
optional :: recl
264 type(
mpi_grp_t),
intent(in),
optional :: grp
266 character(len=20) :: status_, form_, position_
267 character(len=MAX_PATH_LEN) :: file_
270 character(len=100) :: io_emsg
273 if (
present(grp))
then
285 if (
present(status)) status_ = status
287 if (
present(form)) form_ = form
289 if (
present(position)) position_ = position
295 if (
present(recl))
then
296 open(newunit=iunit, file=trim(file_), status=trim(status_), form=trim(form_), &
297 recl=recl, action=trim(action), position=trim(position_), iostat=iostat, iomsg=io_emsg)
299 open(newunit=iunit, file=trim(file_), status=trim(status_), form=trim(form_), &
300 action=trim(action), position=trim(position_), iostat=iostat, iomsg=io_emsg)
303 io_open_count = io_open_count + 1
305 if (iostat /= 0)
then
307 write(stderr,
'(a,a)')
'*** IO Error: ', trim(io_emsg)
316 if (grp_%size > 1)
then
317 call grp_%bcast(iunit, 1, mpi_integer, 0)
325 integer,
intent(inout) :: iunit
326 type(
mpi_grp_t),
intent(in),
optional :: grp
330 if (
present(grp))
then
340 io_close_count = io_close_count + 1
349 integer,
intent(in) :: ounit
350 character(len=*),
intent(in) :: filename
352 integer :: iunit, err
353 character(len=80) :: line
357 open(newunit=iunit, file=filename, iostat=err, action=
'read', status=
'old')
360 read(iunit, fmt=
'(a80)', iostat=err) line
362 write(ounit,
'(a)') trim(line)
376 character(len = *),
intent(in) :: path
379 i = index(path,
".", back = .
true.)
380 j = index(path(i+1:),
"/")
381 if (i == 0 .or. j /= 0)
then
397 if (
io_file_exists(
'enable_debug_mode', msg=
'Enabling DebugMode'))
then
403 call loct_rm(
'enable_debug_mode')
408 if (
io_file_exists(
'disable_debug_mode', msg=
'Disabling DebugMode'))
then
411 call loct_rm(
'disable_debug_mode')
422 logical function io_file_exists(filename, msg)
result(file_exists)
423 character(len=*),
intent(in) :: filename
424 character(len=*),
optional,
intent(in) :: msg
426 file_exists = .false.
427 inquire(file=trim(filename), exist=file_exists)
428 if (file_exists .and.
present(msg))
then
429 write(stderr,
'(a)') trim(msg)
437 character(len=*),
intent(in) :: dir
445 subroutine iopar_read(grp, iunit, lines, n_lines, ierr)
447 integer,
intent(in) :: iunit
448 character(len=*),
intent(out) :: lines(:)
449 integer,
intent(in) :: n_lines
450 integer,
intent(out) :: ierr
454 assert(n_lines <=
size(lines))
458 read(iunit,
'(a)', iostat=ierr) lines(il)
463 call grp%bcast(ierr, 1, mpi_integer, 0)
464 call grp%bcast(lines(1), len(lines(1))*n_lines, mpi_character, 0)
471 integer,
intent(in) :: iunit
483 integer,
intent(in) :: iunit
484 character(len=*),
intent(in) :: line
485 integer,
intent(out) :: ierr
487 character(len=80) :: read_line
492 read(iunit,
'(a)', iostat=ierr) read_line
493 if (ierr /= 0 .or. trim(line) == trim(read_line))
exit
497 call grp%bcast(ierr, 1, mpi_integer, 0)
504 integer,
intent(in) :: iunit
506 character(len=1) :: a
520 count = io_open_count
547 integer,
intent(in) :: iio
549 integer :: open_count
551 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)
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)
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)
logical function, public loct_dir_exists(dirname)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
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.