55 character(len = *),
public,
parameter ::
curdir =
'.'
57 character(len = *),
public,
parameter ::
pardir =
'..'
59 character(len = *),
public,
parameter ::
sep =
'/'
61 character(len = *),
public,
parameter ::
extsep =
'.'
63 character(len = *),
public,
parameter ::
linesep =
'\n'
65 character(len = *),
public,
parameter ::
devnull =
'/dev/null'
81 subroutine get_cwd(path, status, verbose, raise)
83 use f90_unix_dir,
only : getcwd
86 use ifport,
only : getcwd
90 character(*),
intent(out) :: path
91 integer(i4),
intent(out),
optional :: status
92 logical,
intent(in),
optional :: verbose
93 logical,
intent(in),
optional :: raise
95 integer(i4) :: status_
99 if (
present(raise) ) raise_ = raise
101 raise_ = raise_ .and. .not.
present(status)
104 call getcwd(path, errno=status_)
107 status_ = getcwd(path)
110 if (status_ /= 0)
call path_msg(
"Can't determine current working directory.", verbose=verbose, raise=raise_)
111 if (
present(status) ) status = status_
121 use f90_unix_dir,
only : chdir
124 use ifport,
only : chdir
128 character(*),
intent(in) :: path
129 integer(i4),
intent(out),
optional :: status
130 logical,
intent(in),
optional :: verbose
131 logical,
intent(in),
optional :: raise
133 integer(i4) :: status_
137 if (
present(raise) ) raise_ = raise
139 raise_ = raise_ .and. .not.
present(status)
142 call chdir(trim(path), errno=status_)
145 status_ = chdir(path)
148 if (status_ /= 0)
call path_msg(
"Can't open directory: ", trim(path), verbose, raise_)
149 if (
present(status) ) status = status_
161 character(len=*),
intent(in) :: path
162 logical,
intent(out),
optional :: answer
163 logical,
intent(in),
optional :: verbose
164 logical,
intent(in),
optional :: raise
169 if (.not. exists)
call path_msg(
"Path does not exist: ", path, verbose, raise)
170 if (
present(answer)) answer = exists
182 character(len=*),
intent(in) :: path
183 logical,
intent(out),
optional :: answer
184 logical,
intent(in),
optional :: verbose
185 logical,
intent(in),
optional :: raise
190 if (.not. isfile)
call path_msg(
"File does not exist: ", path, verbose, raise)
191 if (
present(answer)) answer = isfile
203 character(len=*),
intent(in) :: path
204 logical,
intent(out),
optional :: answer
205 logical,
intent(in),
optional :: verbose
206 logical,
intent(in),
optional :: raise
211 if (.not. isdir)
call path_msg(
"Directory does not exist: ", path, verbose, raise)
212 if (
present(answer)) answer = isdir
222 character(len=*),
intent(in) :: path
234 character(len=*),
intent(in) :: path
248 character(len=*),
intent(in) :: path
252 inquire(directory=trim(path), exist=
path_isdir)
267 character(len=*),
intent(in) :: path
281 character(len=*),
intent(in) :: path
285 do i=len_trim(path), 0, -1
287 if (path(i:i) /=
sep)
exit
310 character(len=*),
intent(in) :: path
311 character(len=*),
intent(out),
optional :: root
312 character(len=*),
intent(out),
optional :: ext
314 integer :: lead_i, dot_i, sep_i
315 character(len=len_trim(path)) :: head, tail
318 sep_i = index(trim(path),
sep, back=.true.)
320 tail = path(sep_i+1:len_trim(path))
323 do lead_i = 1, len_trim(tail) + 1
324 if ( lead_i > len_trim(tail) )
exit
325 if ( tail(lead_i:lead_i) /=
extsep )
exit
329 dot_i = index(trim(tail),
extsep, back=.true.)
331 if ( dot_i > lead_i )
then
333 if (
present(ext)) ext = tail(dot_i:len_trim(tail))
334 if (
present(root)) root = trim(head) // tail(1:dot_i-1)
337 if (
present(ext)) ext =
""
338 if (
present(root)) root = trim(head) // trim(tail)
361 character(len=*),
intent(in) :: path
362 character(len=*),
intent(out),
optional :: head
363 character(len=*),
intent(out),
optional :: tail
366 character(len=len_trim(path)) :: head_
369 i = index(trim(path),
sep, back=.true.)
373 if (
present(tail)) tail = trim(path)
374 if (
present(head)) head =
''
376 if (
present(tail)) tail = path((i+1):len_trim(path))
377 if (.not.
present(head))
return
380 do i=len_trim(head_), 0, -1
382 if (head_(i:i) /=
sep)
exit
384 if (i == 0) i = len_trim(head_)
397 character(len=*),
intent(in) :: path
398 character(len=len_trim(path)),
allocatable,
intent(out) :: parts(:)
401 character(len=len_trim(path)) :: temp, comp
407 do while (len_trim(temp) > 0)
410 if (len_trim(temp) == 2)
then
419 if (len_trim(comp) > 0)
call append(parts, comp)
423 if (
size(parts) > 1) parts = [(parts(i), i =
size(parts), 1, -1)]
434 character(len=*),
intent(in) :: path
435 character(:),
allocatable :: dirname
437 character(len=len_trim(path)) :: temp
451 character(len=*),
intent(in) :: path
452 character(:),
allocatable :: basename
454 character(len=len_trim(path)) :: temp
457 basename = trim(temp)
467 character(len=*),
intent(in) :: path
468 character(:),
allocatable :: root
470 character(len=len_trim(path)) :: temp
483 character(len=*),
intent(in) :: path
484 character(:),
allocatable :: ext
486 character(len=len_trim(path)) :: temp
499 character(len=*),
intent(in) :: path
500 character(:),
allocatable :: stem
502 character(len=len_trim(path)) :: temp, tail
517 character(len=*),
intent(in) :: path
518 character(:),
allocatable :: posix
520 posix = trim(replace_text(path,
"\\",
sep))
534 character(len=*),
intent(in) :: path
535 character(:),
allocatable :: normpath
537 character(len=len_trim(path)) :: temp, comp, root
538 character(len=len_trim(path)),
allocatable :: comps_raw(:), comps(:)
545 if (
size(comps_raw) == 0)
then
554 do i = 1,
size(comps_raw)
556 if ( len_trim(comp) == 0 ) cycle
557 if ( trim(comp) ==
curdir ) cycle
559 if ( trim(comp) /=
pardir )
then
562 else if (.not. has_root .and. (
size(comps) == 0))
then
565 else if (
size(comps) > 0 )
then
566 if (comps(
size(comps)) ==
pardir)
then
569 else if (.not.
path_isroot(comps(
size(comps))))
then
577 if (
size(comps) > 0)
then
592 character(len=*),
intent(in) :: path
593 character(:),
allocatable :: abspath
595 character(len=max_path_len) :: cwd
610 character(len=*),
intent(in) :: p1, p2
611 character(:),
allocatable :: join
618 if ( (len_trim(p1) > 0) .and. .not.
endswith(p1,
sep) )
then
619 join = trim(p1) //
sep // trim(p2)
621 join = trim(p1) // trim(p2)
632 function path_join_char_opt(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16)
result(join)
635 character(len=*),
intent(in) :: p1
636 character(len=*),
intent(in),
optional :: p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16
637 character(:),
allocatable :: join
665 character(len=*),
dimension(:),
intent(in) :: paths
666 character(:),
allocatable :: join
671 do i = 1,
size(paths)
678 subroutine path_msg(msg, path, verbose, raise)
681 character(len=*),
intent(in),
optional :: msg
682 character(len=*),
intent(in),
optional :: path
683 logical,
intent(in),
optional :: verbose
684 logical,
intent(in),
optional :: raise
689 if (
present(raise)) raise_ = raise
693 call message(msg, trim(path), show=verbose)
696 end subroutine path_msg
702 character(len=*),
allocatable,
intent(inout) :: arr(:)
704 character(:),
allocatable :: temp(:)
706 if (.not.
allocated(arr))
return
707 if (
size(arr) == 0)
return
709 allocate(
character(len(arr(1))) :: temp(size(arr)-1))
710 temp(:) = arr(1:
size(arr)-1)
711 call move_alloc(temp, arr)
Append (rows) scalars, vectors, and matrixes onto existing array.
Join given path segments with separator if needed.
Append values on existing arrays.
Define number representations.
integer, parameter i4
4 Byte Integer Kind
Write out concatenated strings.
subroutine, public error_message(t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15, t16, uni, advance, show, raise, reset_format)
Write out an error message to stderr and call stop 1.
subroutine, public message(t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15, t16, uni, advance, show, reset_format)
Write out an error message to stdout.
Path and directory management.
character(:) function, allocatable, public path_stem(path)
Return the final path component without its suffix.
subroutine, public check_path_isdir(path, answer, verbose, raise)
Checks whether a given path exists and describes a directory.
logical function, public path_isfile(path)
Return .true. if path is an existing regular file.
character(:) function, allocatable, public path_root(path)
Return the path without its suffix.
character(:) function, allocatable, public path_dirname(path)
Return the directory name of pathname path.
character(len=*), parameter, public curdir
The constant string used by the operating system to refer to the current directory.
character(:) function, allocatable, public path_abspath(path)
Return a normalized absolutized version of the given path.
character(:) function, allocatable path_join_char_opt(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16)
Join given path segments with separator if needed.
logical function, public path_exists(path)
Return .true. if path refers to an existing path.
subroutine, public change_dir(path, status, verbose, raise)
Change current working directory.
character(:) function, allocatable, public path_basename(path)
Return the base name of pathname path.
subroutine, public get_cwd(path, status, verbose, raise)
Get the current working directory.
character(:) function, allocatable, public path_as_posix(path)
Return the string representation of the path with forward (/) slashes.
character(len=*), parameter, public sep
The character used by the operating system to separate pathname components.
subroutine pop(arr)
character array pop
logical function, public path_isroot(path)
Return .true. if path is root ('/' or '//' or '///' and so on).
subroutine, public path_splitext(path, root, ext)
Splitting the path into root and ext.
character(:) function, allocatable path_join_char(p1, p2)
Join two path segments with separator if needed.
subroutine, public path_parts(path, parts)
Splitting the path into its components.
character(:) function, allocatable, public path_normpath(path)
Normalize a pathname by collapsing redundant separators and up-level references.
character(len=*), parameter, public pardir
The constant string used by the operating system to refer to the parent directory.
subroutine, public path_split(path, head, tail)
Splitting the path into head and tail.
character(:) function, allocatable, public path_ext(path)
Return the file extension of the final path component.
logical function, public path_isdir(path)
Return .true. if path is an existing directory.
character(:) function, allocatable path_join_arr(paths)
Join given path segments with separator if needed.
character(len=*), parameter, public extsep
The character which separates the base filename from the extension.
subroutine, public check_path_exists(path, answer, verbose, raise)
Checks whether a given path exists.
subroutine, public check_path_isfile(path, answer, verbose, raise)
Checks whether a given path exists and describes a file.
logical function, public path_isabs(path)
Return .true. if path is an absolute pathname.
integer(i4), save, public max_path_len
Maximum length of a path (16 max. length components).
character(len=*), parameter, public linesep
The string used to separate (or, rather, terminate) lines on the current platform.
integer(i4), save, public max_path_comp_len
Maximum length of a path component (folder/file names).
character(len=*), parameter, public devnull
The file path of the null device.
logical function, public startswith(string, start, strip)
Checks if string starts with character(s)
logical function, public endswith(string, suffix, strip)
Checks if (maybe trimmed) string ends with given character(s)