0.6.2-dev0
FORCES
FORtran lib for Comp. Env. Sys.
Loading...
Searching...
No Matches
mo_os Module Reference

Path and directory management. More...

Data Types

interface  path_join
 Join given path segments with separator if needed. More...
 

Functions/Subroutines

subroutine, public get_cwd (path, status, verbose, raise)
 Get the current working directory.
 
subroutine, public change_dir (path, status, verbose, raise)
 Change current working directory.
 
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.
 
subroutine, public check_path_isdir (path, answer, verbose, raise)
 Checks whether a given path exists and describes a directory.
 
logical function, public path_exists (path)
 Return .true. if path refers to an existing path.
 
logical function, public path_isfile (path)
 Return .true. if path is an existing regular file.
 
logical function, public path_isdir (path)
 Return .true. if path is an existing directory.
 
logical function, public path_isabs (path)
 Return .true. if path is an absolute pathname.
 
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.
 
subroutine, public path_split (path, head, tail)
 Splitting the path into head and tail.
 
subroutine, public path_parts (path, parts)
 Splitting the path into its components.
 
character(:) function, allocatable, public path_dirname (path)
 Return the directory name of pathname path.
 
character(:) function, allocatable, public path_basename (path)
 Return the base name of pathname path.
 
character(:) function, allocatable, public path_root (path)
 Return the path without its suffix.
 
character(:) function, allocatable, public path_ext (path)
 Return the file extension of the final path component.
 
character(:) function, allocatable, public path_stem (path)
 Return the final path component without its suffix.
 
character(:) function, allocatable, public path_as_posix (path)
 Return the string representation of the path with forward (/) slashes.
 
character(:) function, allocatable, public path_normpath (path)
 Normalize a pathname by collapsing redundant separators and up-level references.
 
character(:) function, allocatable, public path_abspath (path)
 Return a normalized absolutized version of the given path.
 
character(:) function, allocatable path_join_char (p1, p2)
 Join two path segments with separator if needed.
 
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.
 
character(:) function, allocatable path_join_arr (paths)
 Join given path segments with separator if needed.
 
subroutine path_msg (msg, path, verbose, raise)
 
subroutine pop (arr)
 character array pop
 

Variables

character(len=*), parameter, public curdir = '.'
 The constant string used by the operating system to refer to the current directory.
 
character(len=*), parameter, public pardir = '..'
 The constant string used by the operating system to refer to the parent directory.
 
character(len=*), parameter, public sep = '/'
 The character used by the operating system to separate pathname components.
 
character(len=*), parameter, public extsep = '.'
 The character which separates the base filename from the extension.
 
character(len=*), parameter, public linesep = '\n'
 The string used to separate (or, rather, terminate) lines on the current platform.
 
character(len=*), parameter, public devnull = '/dev/null'
 The file path of the null device.
 
integer(i4), save, public max_path_comp_len = 256_i4
 Maximum length of a path component (folder/file names).
 
integer(i4), save, public max_path_len = 4096_i4
 Maximum length of a path (16 max. length components).
 

Detailed Description

Path and directory management.

Path handling and existence checks for files and directories.

Changelog
  • Nicola Doering, Aug 2020
    • module implementation
  • Sebastian Mueller, Jan 2023
    • changed signatures (path, answer, verbose, raise) for path_exists, path_isfile and path_isdir
    • respect show_msg and show_err from mo_message
    • simplify inquire logic

Function/Subroutine Documentation

◆ change_dir()

subroutine, public mo_os::change_dir ( character(*), intent(in)  path,
integer(i4), intent(out), optional  status,
logical, intent(in), optional  verbose,
logical, intent(in), optional  raise 
)

Change current working directory.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathpath to change CWD to
[out]statuserror status (will prevent error raise if present)
[in]verboseBe verbose or not (default: setting of SHOW_MSG/SHOW_ERR)
[in]raiseThrow an error if directory can't be opened (default: .true.)

Definition at line 119 of file mo_os.F90.

◆ check_path_exists()

subroutine, public mo_os::check_path_exists ( character(len=*), intent(in)  path,
logical, intent(out), optional  answer,
logical, intent(in), optional  verbose,
logical, intent(in), optional  raise 
)

Checks whether a given path exists.

Author
Nicola Doering
Date
Aug 2020
Parameters
[in]pathgiven path
[out]answerresult
[in]verboseBe verbose or not (default: setting of SHOW_MSG/SHOW_ERR)
[in]raiseThrow an error if path does not exist (default: .false.)

Definition at line 157 of file mo_os.F90.

References path_exists().

Here is the call graph for this function:

◆ check_path_isdir()

subroutine, public mo_os::check_path_isdir ( character(len=*), intent(in)  path,
logical, intent(out), optional  answer,
logical, intent(in), optional  verbose,
logical, intent(in), optional  raise 
)

Checks whether a given path exists and describes a directory.

Author
Nicola Doering
Date
Aug 2020
Parameters
[in]pathgiven path
[out]answerresult
[in]verboseBe verbose or not (default: setting of SHOW_MSG/SHOW_ERR)
[in]raiseThrow an error if dir does not exist (default: .false.)

Definition at line 199 of file mo_os.F90.

References path_isdir().

Here is the call graph for this function:

◆ check_path_isfile()

subroutine, public mo_os::check_path_isfile ( character(len=*), intent(in)  path,
logical, intent(out), optional  answer,
logical, intent(in), optional  verbose,
logical, intent(in), optional  raise 
)

Checks whether a given path exists and describes a file.

Author
Nicola Doering
Date
Aug 2020
Parameters
[in]pathgiven path
[out]answerresult
[in]verboseBe verbose or not (default: setting of SHOW_MSG/SHOW_ERR)
[in]raiseThrow an error if file does not exist (default: .false.)

Definition at line 178 of file mo_os.F90.

References path_isfile().

Here is the call graph for this function:

◆ get_cwd()

subroutine, public mo_os::get_cwd ( character(*), intent(out)  path,
integer(i4), intent(out), optional  status,
logical, intent(in), optional  verbose,
logical, intent(in), optional  raise 
)

Get the current working directory.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[out]paththe current working directory
[out]statuserror status (will prevent error raise if present)
[in]verboseBe verbose or not (default: setting of SHOW_MSG/SHOW_ERR)
[in]raiseThrow an error if current directory can't be determined (default: .true.)

Definition at line 81 of file mo_os.F90.

Referenced by path_abspath().

Here is the caller graph for this function:

◆ path_abspath()

character(:) function, allocatable, public mo_os::path_abspath ( character(len=*), intent(in)  path)

Return a normalized absolutized version of the given path.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path
Returns
stem

Definition at line 590 of file mo_os.F90.

References get_cwd(), path_join_char(), and path_normpath().

Here is the call graph for this function:

◆ path_as_posix()

character(:) function, allocatable, public mo_os::path_as_posix ( character(len=*), intent(in)  path)

Return the string representation of the path with forward (/) slashes.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path
Returns
posix version of the path

Definition at line 514 of file mo_os.F90.

References sep.

◆ path_basename()

character(:) function, allocatable, public mo_os::path_basename ( character(len=*), intent(in)  path)

Return the base name of pathname path.

This is the second element of the pair returned by passing path to the subroutine path_split.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 449 of file mo_os.F90.

References path_split().

Here is the call graph for this function:

◆ path_dirname()

character(:) function, allocatable, public mo_os::path_dirname ( character(len=*), intent(in)  path)

Return the directory name of pathname path.

This is the first element of the pair returned by passing path to the subroutine path_split.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 432 of file mo_os.F90.

References path_split().

Here is the call graph for this function:

◆ path_exists()

logical function, public mo_os::path_exists ( character(len=*), intent(in)  path)

Return .true. if path refers to an existing path.

Author
Sebastian Mueller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 220 of file mo_os.F90.

References path_exists(), path_isdir(), and path_isfile().

Referenced by check_path_exists(), and path_exists().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_ext()

character(:) function, allocatable, public mo_os::path_ext ( character(len=*), intent(in)  path)

Return the file extension of the final path component.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 481 of file mo_os.F90.

References path_splitext().

Here is the call graph for this function:

◆ path_isabs()

logical function, public mo_os::path_isabs ( character(len=*), intent(in)  path)

Return .true. if path is an absolute pathname.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 264 of file mo_os.F90.

References path_isabs(), sep, and mo_string_utils::startswith().

Referenced by path_isabs(), and path_join_char().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_isdir()

logical function, public mo_os::path_isdir ( character(len=*), intent(in)  path)

Return .true. if path is an existing directory.

Author
Sebastian Mueller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 246 of file mo_os.F90.

References path_isdir(), and sep.

Referenced by check_path_isdir(), path_exists(), path_isdir(), and path_isfile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_isfile()

logical function, public mo_os::path_isfile ( character(len=*), intent(in)  path)

Return .true. if path is an existing regular file.

Author
Sebastian Mueller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 232 of file mo_os.F90.

References path_isdir(), and path_isfile().

Referenced by check_path_isfile(), path_exists(), and path_isfile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_isroot()

logical function, public mo_os::path_isroot ( character(len=*), intent(in)  path)

Return .true. if path is root ('/' or '//' or '///' and so on).

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 278 of file mo_os.F90.

References path_isroot(), sep, and mo_string_utils::startswith().

Referenced by path_isroot(), path_normpath(), and path_parts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_join_arr()

character(:) function, allocatable mo_os::path_join_arr ( character(len=*), dimension(:), intent(in)  paths)
private

Join given path segments with separator if needed.

If a segment is an absolute path, the previous ones will be ignored.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathsgiven paths
Returns
joined paths

Definition at line 663 of file mo_os.F90.

Referenced by path_normpath().

Here is the caller graph for this function:

◆ path_join_char()

character(:) function, allocatable mo_os::path_join_char ( character(len=*), intent(in)  p1,
character(len=*), intent(in)  p2 
)
private

Join two path segments with separator if needed.

If the second segment is an absolute path, the first one will be ignored.

Author
Sebastian Müller
Date
Mar 2023
Returns
joined paths

Definition at line 607 of file mo_os.F90.

References mo_string_utils::endswith(), path_isabs(), and sep.

Referenced by path_abspath(), mo_os::path_join::path_join_arr(), and mo_os::path_join::path_join_char_opt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_join_char_opt()

character(:) function, allocatable mo_os::path_join_char_opt ( character(len=*), intent(in)  p1,
character(len=*), intent(in), optional  p2,
character(len=*), intent(in), optional  p3,
character(len=*), intent(in), optional  p4,
character(len=*), intent(in), optional  p5,
character(len=*), intent(in), optional  p6,
character(len=*), intent(in), optional  p7,
character(len=*), intent(in), optional  p8,
character(len=*), intent(in), optional  p9,
character(len=*), intent(in), optional  p10,
character(len=*), intent(in), optional  p11,
character(len=*), intent(in), optional  p12,
character(len=*), intent(in), optional  p13,
character(len=*), intent(in), optional  p14,
character(len=*), intent(in), optional  p15,
character(len=*), intent(in), optional  p16 
)
private

Join given path segments with separator if needed.

If a segment is an absolute path, the previous ones will be ignored.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]p1initial path
Returns
joined paths

Definition at line 632 of file mo_os.F90.

◆ path_msg()

subroutine mo_os::path_msg ( character(len=*), intent(in), optional  msg,
character(len=*), intent(in), optional  path,
logical, intent(in), optional  verbose,
logical, intent(in), optional  raise 
)
private

Definition at line 678 of file mo_os.F90.

◆ path_normpath()

character(:) function, allocatable, public mo_os::path_normpath ( character(len=*), intent(in)  path)

Normalize a pathname by collapsing redundant separators and up-level references.

Normalize a pathname by collapsing redundant separators and up-level references so that A//B, A/B/, A/./B and A/foo/../B all become A/B. This string manipulation may change the meaning of a path that contains symbolic links.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path
Returns
normalized path

Definition at line 531 of file mo_os.F90.

References curdir, pardir, path_isroot(), path_join_arr(), path_parts(), and pop().

Referenced by path_abspath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_parts()

subroutine, public mo_os::path_parts ( character(len=*), intent(in)  path,
character(len=len_trim(path)), dimension(:), intent(out), allocatable  parts 
)

Splitting the path into its components.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path
[out]partsparts of the given path

Definition at line 394 of file mo_os.F90.

References path_isroot(), path_split(), and sep.

Referenced by path_normpath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_root()

character(:) function, allocatable, public mo_os::path_root ( character(len=*), intent(in)  path)

Return the path without its suffix.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 465 of file mo_os.F90.

References path_splitext().

Here is the call graph for this function:

◆ path_split()

subroutine, public mo_os::path_split ( character(len=*), intent(in)  path,
character(len=*), intent(out), optional  head,
character(len=*), intent(out), optional  tail 
)

Splitting the path into head and tail.

Splitting the path name into a pair head and tail. Here, tail is the last path name component and head is everything leading up to that. If the path ends with an '/' tail is returned empty and if there is no '/' in path head is returned empty. Trailing '/'es are stripped from head unless it is the root.

Changelog
  • Sebastian Müller Mar 2023
    • remove trailing '/' from head unleass it is root (e.g. '/' or '//' or '///' and so on)
    • make head and tail optional
Author
Nicola Doering
Date
Aug 2020
Parameters
[in]pathgiven path
[out]headeverything leading up to the last path component
[out]taillast pathname component

Definition at line 357 of file mo_os.F90.

References sep.

Referenced by mo_cli::new_cli_parser(), path_basename(), path_dirname(), path_parts(), and path_stem().

Here is the caller graph for this function:

◆ path_splitext()

subroutine, public mo_os::path_splitext ( character(len=*), intent(in)  path,
character(len=*), intent(out), optional  root,
character(len=*), intent(out), optional  ext 
)

Splitting the path into root and ext.

Splitting the path name into a pair root and ext. Here, ext stands for extension and has the extension string of the specified path while root is everything except this extension.

Changelog
  • Sebastian Müller Mar 2023
    • don't check for folder
    • ignore leading dots in tail of the path
    • make root and ext optional
Author
Nicola Doering
Date
Aug 2020
Parameters
[in]pathgiven path
[out]rootroot part of path without extension
[out]extextension of given path (starting with ".")

Definition at line 305 of file mo_os.F90.

References mo_string_utils::endswith(), extsep, and sep.

Referenced by path_ext(), path_root(), and path_stem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_stem()

character(:) function, allocatable, public mo_os::path_stem ( character(len=*), intent(in)  path)

Return the final path component without its suffix.

Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]pathgiven path

Definition at line 497 of file mo_os.F90.

References path_split(), and path_splitext().

Here is the call graph for this function:

◆ pop()

subroutine mo_os::pop ( character(len=*), dimension(:), intent(inout), allocatable  arr)
private

character array pop

Definition at line 699 of file mo_os.F90.

Referenced by path_normpath().

Here is the caller graph for this function:

Variable Documentation

◆ curdir

character(len = *), parameter, public mo_os::curdir = '.'

The constant string used by the operating system to refer to the current directory.

Definition at line 55 of file mo_os.F90.

Referenced by path_normpath().

◆ devnull

character(len = *), parameter, public mo_os::devnull = '/dev/null'

The file path of the null device.

Definition at line 65 of file mo_os.F90.

◆ extsep

character(len = *), parameter, public mo_os::extsep = '.'

The character which separates the base filename from the extension.

Definition at line 61 of file mo_os.F90.

Referenced by path_splitext().

◆ linesep

character(len = *), parameter, public mo_os::linesep = '\n'

The string used to separate (or, rather, terminate) lines on the current platform.

Definition at line 63 of file mo_os.F90.

◆ max_path_comp_len

integer(i4), save, public mo_os::max_path_comp_len = 256_i4

Maximum length of a path component (folder/file names).

Definition at line 67 of file mo_os.F90.

◆ max_path_len

integer(i4), save, public mo_os::max_path_len = 4096_i4

Maximum length of a path (16 max. length components).

Definition at line 69 of file mo_os.F90.

◆ pardir

character(len = *), parameter, public mo_os::pardir = '..'

The constant string used by the operating system to refer to the parent directory.

Definition at line 57 of file mo_os.F90.

Referenced by path_normpath().

◆ sep

character(len = *), parameter, public mo_os::sep = '/'

The character used by the operating system to separate pathname components.

Definition at line 59 of file mo_os.F90.

Referenced by path_as_posix(), path_isabs(), path_isdir(), path_isroot(), path_join_char(), path_parts(), path_split(), and path_splitext().