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

Generate and return a unique (directory or file) path name in the temporary directory of the system or if there is none, in the current working directory of the program, optionally with the user-specified file name segments.
More...

Detailed Description

Generate and return a unique (directory or file) path name in the temporary directory of the system or if there is none, in the current working directory of the program, optionally with the user-specified file name segments.

The procedures under this generic interface return a full unique path that is,

  1. optionally followed by the user-specified prefix,
  2. optionally followed by the file extension ext, that can be either
    1. a string with pattern .*, if a file path is desired as the output, or
    2. a string that ends with an appropriate path-separator symbol of the platform, if a directory path is desired as the output.

The procedures under this generic interface use the current date and time and the process ID to generate new unique non-existing directory or file paths.
The general format of the output directory path is the following:

  <tempdir><prefix><ccyymmdd><sep><hhmmss><sep><sss><sep>pid<sep><pid><ext>

where,

  1. <tempdir> is replaced with the operating system temporary directory or if none is detected, with the current runtime working directory,
  2. <prefix> is replaced with the contents of the input argument prefix or its default value,
  3. <sep> is replaced with the contents of the input argument sep or its default value,
  4. <ccyymmdd> is replaced with the current century, year, month, and day, each represented by two characters,
  5. <hhmmss> is replaced with the current hour hh, minute mm, second ss, in the specified ordered,
  6. <sss> is replaced with the current millisecond mmm,
  7. <pid> is replaced with the user-specified processor ID pid which can be the output of getImageID.
  8. <ext> is replaced with the contents of the input argument ext or its default value.

If no unique path is found after 1000 attempts, the procedure returns and reports a failure.

Parameters
[in]prefix: The input scalar character of default kind SK containing the requested input prefix to the path that appears first in the newly-constructed path.
(optional, default = "new"//sep where sep is the other optional argument of the interface.)
[in]sep: The input scalar character of default kind SK containing the requested separator character to be inserted between the individual components of the new path to be constructed.
This is different from the system shell directory separator.
(optional, default = "_")
[in]ext: The input scalar character of default kind SK containing the requested input file extension or directory path-separator to appear at the end of the path.
(optional, default = "")
[in]pid: The input scalar integer of default kind IK representing the processor ID (e.g., processor MPI rank or Coarray image ID).
If present, it will be used in the generated path to make it processor-specific.
The processor MPI rank or Coarray image ID can be for example obtained by calling getImageID.
(optional, default = getImageID())
[out]failed: The output logical of default kind LK that is .true. if and only if the procedure fails to find a new unique (non-existent) path.
(optional, if missing and the procedure fails, then the program will halt by calling error stop.)
Returns
pathTemp : The output allocatable scalar of type character of default kind SK, containing a new unique non-existent temporary (directory or file) path, either in the OS temporary directory or in the current working directory.


Possible calling interfaces

pathTemp = getPathTemp(prefix = prefix, sep = sep, ext = ext, failed = failed)
Generate and return a unique (directory or file) path name in the temporary directory of the system o...
This module contains classes and procedures for manipulating system file/folder paths.
Definition: pm_sysPath.F90:274
Warning
Avoid the use of Windows reserved (forbidden) characters WINDOWS_RESERVED_STR in path names.
Although such characters work fine on Unix systems, the Windows OS will not be able to gracefully handle such paths.
In particular, avoid the use of forward or backslash in path names (it is fine to use them as path-separator symbols).
The input ext argument, if it is present and contains a file extension, must the proper file extension separator symbol (e.g., .).
The file extension separator (.) will not be added to the input extension by this procedure.
Remarks
On Windows Operating Systems (OS), the choice of the path-separator depends on the processor runtime shell being used.
The Windows Batch terminal (CMD) can handle paths that are separated via either DIR_SEP_WINDOWS or DIR_SEP_POSIX or even both (although paths containing POSIX separators must be quoted).
However, Unix-like Shells like Git Bash, Cygwin, etc. only recognize DIR_SEP_POSIX even on Windows OS.
Therefore, to avoid the use of wrong path-separator for the parent directory of the path on Windows OS, the following steps are taken:
  1. If the runtime shell is Windows-based and the temporary directory does not end with a directory separator recognized by Windows (DIR_SEP_WINDOWS_ALL), the directory will be suffixed with a Windows-style path-separator.
  2. Otherwise, if the temporary directory does not end with a directory separator (DIR_SEP_POSIX_ALL) recognized by POSIX-style runtime shells (including Fish), then the temporary directory will be suffixed with a POSIX-style path-separator.
The procedures under discussion are impure.
See also
getPathNew
getPathTemp
isFailedMakeDir
isFailedMakeDirTemp
getPathHostNameIndex


Example usage

1program example
2
3 use pm_kind, only: LK, IK
4 use pm_kind, only: SK ! all processor types and kinds are supported.
5 use pm_io, only: display_type
6 use pm_sysPath, only: getPathTemp
7
8 implicit none
9
10 logical(LK) :: failed
11
12 type(display_type) :: disp
13 disp = display_type(file = "main.out.F90")
14
15 call disp%skip()
16 call disp%show("getPathTemp()")
17 call disp%show( getPathTemp() , deliml = SK_"""" )
18 call disp%skip()
19
20 call disp%skip()
21 call disp%show("getPathTemp(prefix = SK_'paramonte')")
22 call disp%show( getPathTemp(prefix = SK_'paramonte') , deliml = SK_"""" )
23 call disp%skip()
24
25 call disp%skip()
26 call disp%show("getPathTemp(prefix = SK_'paramonte', ext = SK_'.txt')")
27 call disp%show( getPathTemp(prefix = SK_'paramonte', ext = SK_'.txt') , deliml = SK_"""" )
28 call disp%skip()
29
30 call disp%skip()
31 call disp%show("getPathTemp(prefix = SK_'paramonte', ext = SK_'.txt', pid = 3_IK)")
32 call disp%show( getPathTemp(prefix = SK_'paramonte', ext = SK_'.txt', pid = 3_IK) , deliml = SK_"""" )
33 call disp%skip()
34
35 call disp%skip()
36 call disp%show("getPathTemp(prefix = SK_'paramonte', pid = 3_IK, failed = failed)")
37 call disp%show( getPathTemp(prefix = SK_'paramonte', pid = 3_IK, failed = failed) , deliml = SK_"""" )
38 call disp%show("failed")
39 call disp%show( failed )
40 call disp%skip()
41
42 call disp%skip()
43 call disp%show("getPathTemp(prefix = SK_'paramonte', sep = SK_'.', pid = 3_IK, failed = failed)")
44 call disp%show( getPathTemp(prefix = SK_'paramonte', sep = SK_'.', pid = 3_IK, failed = failed) , deliml = SK_"""" )
45 call disp%show("failed")
46 call disp%show( failed )
47 call disp%skip()
48
49end 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 IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
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
3"/tmp/new_20240822_211517_394_pid_1"
4
5
6getPathTemp(prefix = SK_'paramonte')
7"/tmp/paramonte20240822_211517_396_pid_1"
8
9
10getPathTemp(prefix = SK_'paramonte', ext = SK_'.txt')
11"/tmp/paramonte20240822_211517_398_pid_1.txt"
12
13
14getPathTemp(prefix = SK_'paramonte', ext = SK_'.txt', pid = 3_IK)
15"/tmp/paramonte20240822_211517_400_pid_3.txt"
16
17
18getPathTemp(prefix = SK_'paramonte', pid = 3_IK, failed = failed)
19"/tmp/paramonte20240822_211517_402_pid_3"
20failed
21F
22
23
24getPathTemp(prefix = SK_'paramonte', sep = SK_'.', pid = 3_IK, failed = failed)
25"/tmp/paramonte20240822.211517.405.pid.3"
26failed
27F
28
29
Test:
test_pm_sysPath
Todo:
High Priority: The current Fortran standard 202x does not allow passing characters of non-default kind to the intrinsic Fortran statements and procedures.
As such, the implementation of this procedure for non-default character kinds leads to compile-time kind mismatch errors.
This procedure should be converted back to a generic interface in the future when non-default character kinds are also fully supported by the intrinsic functions.
Todo:
High Priority: An optional suffix argument can be added in the future. Currently, the path suffix is hard-coded in the procedure, unlike prefix.


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 4498 of file pm_sysPath.F90.


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