ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_sysPath::getIndexDirName Interface Reference

Generate and return the index of the last character of the dirname (directory part) of the input path.
More...

Detailed Description

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.

Parameters
[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,
  1. the constant verbatim or an object of type verbatim_type implying the use of the ParaMonte style described above in extracting the output dirname.
(optional. If missing, the default behavior corresponds to that of the dirname command on POSIX systems. See examples below.)
Returns
index : The output scalar integer of default kind IK containing the position of the last directory separator in the input path.
If there is no directory separator in the path, the output value is 0.


Possible calling interfaces

integer(IK) :: index
index = getIndexDirName(path, dirsep)
index = getIndexDirName(path, dirsep, style)
Generate and return the index of the last character of the dirname (directory part) of the input path...
This module contains classes and procedures for manipulating system file/folder paths.
Definition: pm_sysPath.F90:274
type(verbatim_type), parameter verbatim
The scalar constant of type verbatim_type that can be used to signify the verbatim interpretation of ...
Definition: pm_sysPath.F90:367
Warning
The condition 0 < len(dirsep) must hold for the corresponding input arguments.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Remarks
The procedures under discussion are elemental.
See also
getDirName
getExtName
getFileName
getBaseName
getIndexDirName
getIndexExtName
getIndexBaseName


Example usage

1program example
2
3 use pm_kind, only: LK
4 use pm_kind, only: SK ! all processor types and kinds are supported.
5 use pm_io, only: display_type
7
8 implicit none
9
10 character(:), allocatable :: path
11
12 type(display_type) :: disp
13 disp = display_type(file = "main.out.F90")
14
15 call disp%skip()
16 call disp%show("path = SK_''")
17 path = SK_''
18 call disp%show("getIndexDirName(path, SK_'/')")
19 call disp%show( getIndexDirName(path, SK_'/') )
20 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
21 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
22 call disp%skip()
23
24 call disp%skip()
25 call disp%show("path = SK_'.'")
26 path = SK_'.'
27 call disp%show("getIndexDirName(path, SK_'/')")
28 call disp%show( getIndexDirName(path, SK_'/') )
29 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
30 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
31 call disp%skip()
32
33 call disp%skip()
34 call disp%show("path = SK_'..'")
35 path = SK_'..'
36 call disp%show("getIndexDirName(path, SK_'/')")
37 call disp%show( getIndexDirName(path, SK_'/') )
38 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
39 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
40 call disp%skip()
41
42 call disp%skip()
43 call disp%show("path = SK_'/..'")
44 path = SK_'/..'
45 call disp%show("getIndexDirName(path, SK_'/')")
46 call disp%show( getIndexDirName(path, SK_'/') )
47 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
48 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
49 call disp%skip()
50
51 call disp%skip()
52 call disp%show("path = SK_'../'")
53 path = SK_'../'
54 call disp%show("getIndexDirName(path, SK_'/')")
55 call disp%show( getIndexDirName(path, SK_'/') )
56 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
57 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
58 call disp%skip()
59
60 call disp%skip()
61 call disp%show("path = SK_'/'")
62 path = SK_'/'
63 call disp%show("getIndexDirName(path, SK_'/')")
64 call disp%show( getIndexDirName(path, SK_'/') )
65 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
66 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
67 call disp%skip()
68
69 call disp%skip()
70 call disp%show("path = SK_'/paramonte'")
71 path = SK_'/paramonte'
72 call disp%show("getIndexDirName(path, SK_'/')")
73 call disp%show( getIndexDirName(path, SK_'/') )
74 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
75 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
76 call disp%skip()
77
78 call disp%skip()
79 call disp%show("path = SK_'./paramonte'")
80 path = SK_'./paramonte'
81 call disp%show("getIndexDirName(path, SK_'/')")
82 call disp%show( getIndexDirName(path, SK_'/') )
83 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
84 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
85 call disp%skip()
86
87 call disp%skip()
88 call disp%show("path = SK_'./paramonte/parallel/library.txt'")
89 path = SK_'./paramonte/parallel/library.txt'
90 call disp%show("getIndexDirName(path, SK_'/')")
91 call disp%show( getIndexDirName(path, SK_'/') )
92 call disp%show("path(1:getIndexDirName(path, SK_'/'))")
93 call disp%show( path(1:getIndexDirName(path, SK_'/')) , deliml = """" )
94 call disp%skip()
95
96end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2path = SK_''
3getIndexDirName(path, SK_'/')
4+0
5path(1:getIndexDirName(path, SK_'/'))
6""
7
8
9path = SK_'.'
10getIndexDirName(path, SK_'/')
11+0
12path(1:getIndexDirName(path, SK_'/'))
13""
14
15
16path = SK_'..'
17getIndexDirName(path, SK_'/')
18+0
19path(1:getIndexDirName(path, SK_'/'))
20""
21
22
23path = SK_'/..'
24getIndexDirName(path, SK_'/')
25+1
26path(1:getIndexDirName(path, SK_'/'))
27"/"
28
29
30path = SK_'../'
31getIndexDirName(path, SK_'/')
32+0
33path(1:getIndexDirName(path, SK_'/'))
34""
35
36
37path = SK_'/'
38getIndexDirName(path, SK_'/')
39+1
40path(1:getIndexDirName(path, SK_'/'))
41"/"
42
43
44path = SK_'/paramonte'
45getIndexDirName(path, SK_'/')
46+1
47path(1:getIndexDirName(path, SK_'/'))
48"/"
49
50
51path = SK_'./paramonte'
52getIndexDirName(path, SK_'/')
53+1
54path(1:getIndexDirName(path, SK_'/'))
55"."
56
57
58path = SK_'./paramonte/parallel/library.txt'
59getIndexDirName(path, SK_'/')
60+20
61path(1:getIndexDirName(path, SK_'/'))
62"./paramonte/parallel"
63
64
Test:
test_pm_sysPath
Todo:
High Priority: This procedure should be extended to support non-default character kinds.
Todo:
Normal Priority: The examples should be extended to cover the optional argument 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.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

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.

Author:
Amir Shahmoradi, Tuesday March 7, 2017, 3:50 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 5561 of file pm_sysPath.F90.


The documentation for this interface was generated from the following file: