ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation. |
Generate and return the index of the last character of the dirname (directory part) of the input path
.
More...
Generate and return the index of the last character of the dirname (directory part) of the input path
.
Conventionally, the dirname segment of a path corresponds to the part that starts from the beginning of the path and ends with the character before the last directory separator in the path.
The behavior is consistent with the Unix dirname
software the last directory separator from the output dirname
.
For example, getIndexDirName("./paramonte", "/")
yields 1
as per the dirname
software behavior.
Also, getIndexDirName("/", "/")
yields 1
, consistent with the behavior of Unix dirname
.
Note that getIndexDirName("", "/")
yields 0
, meaning that the dirname
is .
, again consistent with the behavior of Unix dirname
.
This index can be also readily obtained via the Fortran intrinsic index()
as index(path, dirsep, back = .true.)
.
The start index of the dirname segment of the path is trivial (1
) and not returned as the output of this procedure.
For example, if path = "./paramonte"
, then path(1:getIndexDirName(path,"/"))
yields .
.
Alternatively, however, one may be interested in extracting the dirname of a path verbatim while keeping the trailing directory separator character in the output dirname
.
This leads to the more intuitive behavior of yielding 1
as the result of getIndexDirName("/", "/")
(similar to POSIX dirname
software) while yielding 10
as the result of getIndexDirName("paramonte/", "/")
(unlike the POSIX dirname
software which returns 0
corresponding to "."
) In order to also allow this interpretation and behavior, the procedures of this generic interface implement this latter style by setting the style
argument of this generic interface to an object of type verbatim_type such as the constant verbatim.
For more details on this alternative behavior, see the examples below.
[in] | path | : The input scalar character of default kind SK of arbitrary length type parameter containing the path. |
[in] | dirsep | : The input scalar character of default kind SK of arbitrary length type parameter containing the runtime directory separator(s).The directory separator can be obtained from either the dirsep component of an object of type shell_type or getDirSep.The directory separator is \ or / in Windows-based terminals (e.g., CMD or PowerShell) and / in POSIX-compliant shells.When in doubt (for example, in Windows terminals), dirsep can be set to multiple characters, for example dirsep = "/\" .In such a case, the input path will be scanned for the presence of any of the individual characters in dirsep . |
[in] | style | : The input scalar that can be,
dirname command on POSIX systems. See examples below.) |
index
: The output scalar integer
of default kind IK containing the position of the last directory separator in the input path
.path
, the output value is 0
.
Possible calling interfaces ⛓
0 < len(dirsep)
must hold for the corresponding input arguments.CHECK_ENABLED=1
.pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.pure
in release
build and impure
in debug
and testing
builds.elemental
.
Example usage ⛓
ifort
compiler ⛓ ifort
compiler ⛓ gfortran
compiler ⛓ style
.
Final Remarks ⛓
If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.
This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.
Definition at line 5561 of file pm_sysPath.F90.