58 integer,
parameter,
public :: iunit_out = 8
59 integer,
parameter,
public :: iunit_err = 9
60 integer,
parameter :: min_lun=10,
max_lun=10000
61 logical :: lun_is_free(min_lun:max_lun)
62 character(len=MAX_PATH_LEN) :: work_dir
63 integer(int64),
save :: io_open_count
64 integer(int64),
save :: io_close_count
73 logical,
optional,
intent(in) :: defaults
75 character(len=MAX_PATH_LEN) :: filename
82 if (
present(defaults))
then
84 lun_is_free(min_lun:max_lun)=.
true.
93 lun_is_free(min_lun:max_lun)=.
true.
107 if (trim(filename) /=
'-')
then
109 open(stdout, file=filename, status=
'unknown')
123 if (trim(filename) /=
'-')
then
125 open(stderr, file=filename, status=
'unknown')
159 if (
debug%info .or.
debug%interaction_graph .or.
debug%propagation_graph)
then
163 if (
debug%trace_file)
then
175 if (stderr /= 0)
call io_close(stderr)
176 if (stdin /= 5)
call io_close(stdin)
177 if (stdout /= 6)
call io_close(stdout)
184 integer,
intent(out) :: got_lun
186 integer :: iostat, lun
192 do lun = min_lun, max_lun
193 if (lun_is_free(lun))
then
194 inquire(unit=lun, opened=used, iostat=iostat)
196 if (iostat /= 0) used = .
true.
197 lun_is_free(lun) = .false.
210 integer,
intent(in) :: lun
212 if (lun >= min_lun .and. lun <= max_lun) &
213 lun_is_free(lun) = .
true.
219 character(len=MAX_PATH_LEN) function io_workpath(path, namespace)
result(wpath)
220 character(len=*),
intent(in) :: path
221 type(
namespace_t),
optional,
intent(in) :: namespace
223 logical :: absolute_path
227 absolute_path = .false.
228 if (len_trim(path) > 0)
then
229 absolute_path = path(1:1) ==
'/'
233 total_len = len_trim(path)
234 if (.not. absolute_path)
then
235 total_len = total_len + len_trim(work_dir) + 1
236 if (
present(namespace))
then
237 if (namespace%len() > 0) total_len = total_len + namespace%len() + 1
241 write(stderr,
"(A,I5)")
"Path is longer than the maximum path length of ",
max_path_len
244 if (absolute_path)
then
248 wpath = trim(work_dir)
249 if (
present(namespace))
then
251 if (namespace%len() > 0) wpath = trim(wpath) +
"/" + trim(namespace%get(
'/'))
253 wpath = trim(wpath) +
"/" + trim(path)
260 subroutine io_mkdir(fname, namespace, parents)
261 character(len=*),
intent(in) :: fname
262 type(
namespace_t),
optional,
intent(in) :: namespace
263 logical,
optional,
intent(in) :: parents
266 integer :: last_slash, pos, length
269 if (
present(parents)) parents_ = parents
271 if (.not. parents_)
then
275 last_slash = max(index(fname,
"/", .
true.), len_trim(fname))
277 length = index(fname,
'/') - 1
278 do while (pos < last_slash)
280 pos = pos + length + 1
281 length = index(fname(pos:),
"/") - 1
282 if (length < 1) length = len_trim(fname(pos:))
291 subroutine io_rm(fname, namespace)
292 character(len=*),
intent(in) :: fname
293 type(
namespace_t),
optional,
intent(in) :: namespace
301 integer function io_open(file, namespace, action, status, form, position, die, recl, grp)
result(iunit)
302 character(len=*),
intent(in) :: file, action
303 type(
namespace_t),
intent(in),
optional :: namespace
304 character(len=*),
intent(in),
optional :: status, form, position
305 logical,
intent(in),
optional :: die
306 integer,
intent(in),
optional :: recl
307 type(
mpi_grp_t),
intent(in),
optional :: grp
309 character(len=20) :: status_, form_, position_
310 character(len=MAX_PATH_LEN) :: file_
313 character(len=100) :: io_emsg
316 if (
present(grp))
then
328 if (
present(status)) status_ = status
330 if (
present(form)) form_ = form
332 if (
present(position)) position_ = position
334 if (
present(die)) die_ = die
339 write(stderr,
'(a)')
'*** IO Error: Too many files open.'
346 if (
present(recl))
then
347 open(unit=iunit, file=trim(file_), status=trim(status_), form=trim(form_), &
348 recl=recl, action=trim(action), position=trim(position_), iostat=iostat, iomsg=io_emsg)
350 open(unit=iunit, file=trim(file_), status=trim(status_), form=trim(form_), &
351 action=trim(action), position=trim(position_), iostat=iostat, iomsg=io_emsg)
354 io_open_count = io_open_count + 1
356 if (iostat /= 0)
then
360 write(stderr,
'(a,a)')
'*** IO Error: ', trim(io_emsg)
366 if (grp_%size > 1)
then
367 call grp_%bcast(iunit, 1, mpi_integer, 0)
375 integer,
intent(inout) :: iunit
376 type(
mpi_grp_t),
intent(in),
optional :: grp
380 if (
present(grp))
then
390 io_close_count = io_close_count + 1
404 integer,
intent(in) :: iunit
406 integer :: ii, iostat
407 logical :: opened, named
408 character(len=MAX_PATH_LEN) :: filename
409 character(len=11) :: form
411 write(iunit,
'(a)')
'******** io_status ********'
413 inquire(ii, opened=opened, named=named, name=filename, form=form, iostat=iostat)
414 if (iostat == 0)
then
416 if (.not. named) filename =
'No name available'
417 write(iunit,
'(i4,5x,a,5x,a)') ii, form, filename
420 write(iunit,
'(i4,5x,a)') ii,
'Iostat error'
423 write(iunit,
'(a)')
'******** ********'
430 integer,
intent(in) :: ounit
431 character(len=*),
intent(in) :: filename
433 integer :: iunit, err
434 character(len=80) :: line
439 open(unit=iunit, file=filename, iostat=err, action=
'read', status=
'old')
442 read(iunit, fmt=
'(a80)', iostat=err) line
444 write(ounit,
'(a)') trim(line)
458 character(len = *),
intent(in) :: path
461 i = index(path,
".", back = .
true.)
462 j = index(path(i+1:),
"/")
463 if (i == 0 .or. j /= 0)
then
479 if (
io_file_exists(
'enable_debug_mode', msg=
'Enabling DebugMode'))
then
485 call loct_rm(
'enable_debug_mode')
490 if (
io_file_exists(
'disable_debug_mode', msg=
'Disabling DebugMode'))
then
493 call loct_rm(
'disable_debug_mode')
504 logical function io_file_exists(filename, msg)
result(file_exists)
505 character(len=*),
intent(in) :: filename
506 character(len=*),
optional,
intent(in) :: msg
508 file_exists = .false.
509 inquire(file=trim(filename), exist=file_exists)
510 if (file_exists .and.
present(msg))
then
511 write(stderr,
'(a)') trim(msg)
519 character(len=*),
intent(in) :: dir
527 subroutine iopar_read(grp, iunit, lines, n_lines, ierr)
529 integer,
intent(in) :: iunit
530 character(len=*),
intent(out) :: lines(:)
531 integer,
intent(in) :: n_lines
532 integer,
intent(out) :: ierr
536 assert(n_lines <=
size(lines))
540 read(iunit,
'(a)', iostat=ierr) lines(il)
545 call grp%bcast(ierr, 1, mpi_integer, 0)
546 call grp%bcast(lines(1), len(lines(1))*n_lines, mpi_character, 0)
553 integer,
intent(in) :: iunit
565 integer,
intent(in) :: iunit
566 character(len=*),
intent(in) :: line
567 integer,
intent(out) :: ierr
569 character(len=80) :: read_line
574 read(iunit,
'(a)', iostat=ierr) read_line
575 if (ierr /= 0 .or. trim(line) == trim(read_line))
exit
579 call grp%bcast(ierr, 1, mpi_integer, 0)
586 integer,
intent(in) :: iunit
588 character(len=1) :: a
602 count = io_open_count
629 integer,
intent(in) :: iio
631 integer :: open_count
633 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, parameter max_lun
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_assign(got_lun)
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 io_free(lun)
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)
subroutine, public io_status(iunit)
Prints a list of the connected logical units and the names of the associated files.
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.