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

Generate and return the index of the first character of the basename part of the input path.
More...

Detailed Description

Generate and return the index of the first character of the basename part of the input path.

By definition, the basename of a path is the segment that appears after the last directory separator in the path.
As such, the basename of a path can be either empty, a directory, or correspond to a filename (including its extension).
The end index of the basename segment of the path is trivial (len(path)) and not returned as the output of this procedure.
For example, if path = "./paramonte", then path(getIndexBaseName(path,"/"):) yields paramonte.

See also the details of the documentation of the generic interface getIndexDirName and getDirName.

Parameters
[in]path: The input scalar character of default kind SK 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 basename.
(optional. If missing, the default behavior corresponds to that of the basename command on POSIX systems. See examples below.)
Returns
index : The output scalar integer of default kind IK containing the starting position of the basename of the input path.
If the input path does not contain a basename, the output value for index will be len(path) + 1.


Possible calling interfaces

integer(IK) :: index
index = getIndexBaseName(path, dirsep)
index = getIndexBaseName(path, dirsep, verbatim)
Generate and return the index of the first character of the basename 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("getIndexBaseName(path, SK_'/')")
19 call disp%show( getIndexBaseName(path, SK_'/') )
20 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
21 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
28 call disp%show( getIndexBaseName(path, SK_'/') )
29 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
30 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
37 call disp%show( getIndexBaseName(path, SK_'/') )
38 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
39 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
46 call disp%show( getIndexBaseName(path, SK_'/') )
47 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
48 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
55 call disp%show( getIndexBaseName(path, SK_'/') )
56 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
57 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
64 call disp%show( getIndexBaseName(path, SK_'/') )
65 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
66 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
73 call disp%show( getIndexBaseName(path, SK_'/') )
74 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
75 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
82 call disp%show( getIndexBaseName(path, SK_'/') )
83 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
84 call disp%show( path(getIndexBaseName(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("getIndexBaseName(path, SK_'/')")
91 call disp%show( getIndexBaseName(path, SK_'/') )
92 call disp%show("path(getIndexBaseName(path, SK_'/'):)")
93 call disp%show( path(getIndexBaseName(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_''
3getIndexBaseName(path, SK_'/')
4+1
5path(getIndexBaseName(path, SK_'/'):)
6""
7
8
9path = SK_'.'
10getIndexBaseName(path, SK_'/')
11+1
12path(getIndexBaseName(path, SK_'/'):)
13"."
14
15
16path = SK_'..'
17getIndexBaseName(path, SK_'/')
18+1
19path(getIndexBaseName(path, SK_'/'):)
20".."
21
22
23path = SK_'/..'
24getIndexBaseName(path, SK_'/')
25+2
26path(getIndexBaseName(path, SK_'/'):)
27".."
28
29
30path = SK_'../'
31getIndexBaseName(path, SK_'/')
32+1
33path(getIndexBaseName(path, SK_'/'):)
34"../"
35
36
37path = SK_'/'
38getIndexBaseName(path, SK_'/')
39+1
40path(getIndexBaseName(path, SK_'/'):)
41"/"
42
43
44path = SK_'/paramonte'
45getIndexBaseName(path, SK_'/')
46+2
47path(getIndexBaseName(path, SK_'/'):)
48"paramonte"
49
50
51path = SK_'./paramonte'
52getIndexBaseName(path, SK_'/')
53+3
54path(getIndexBaseName(path, SK_'/'):)
55"paramonte"
56
57
58path = SK_'./paramonte/parallel/library.txt'
59getIndexBaseName(path, SK_'/')
60+22
61path(getIndexBaseName(path, SK_'/'):)
62"library.txt"
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 5666 of file pm_sysPath.F90.


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