2%> Return a vector of MATLAB strings containing the
3%> fully-resolved paths matching the input ``pattern``.
6%> This is a ``Hidden`` method of the
class [pm.sampling.Sampler](@ref
Sampler).
8%> \param[in] self : The input parent
object of
class [pm.sampling.Sampler](@ref
Sampler)
9%>
which is **implicitly** passed to
this dynamic method (not by the user).<br>
10%> \param[in] ftype : The input scalar MATLAB
string containing the sampler file type,
11%>
which can be one of the following:
20%> \param[in] pattern : The input scalar MATLAB
string containing either:<br>
22%> <li> a pattern to search
for paths on the current system.<br>
23%> Wildcards may be used
for basenames and
for the directory parts.<br>
24%> If pattern contains directory parts, then these will
25%> be included in the output ``fileList``.<br>
26%> Following wildcards can be used within the specified ``pattern``:
27%> ``*`` : match zero or more characters.<br>
28%> <li> a full
weblink to download and save locally on the system temporary folder.<br>
29%> (**optional**,
default = ``pwd()``)
33%> ``fileList`` : The output vector of MATLAB strings containing the
34%> fully-resolved paths matching the input ``pattern``.<br>
36%> \interface{findfile}
39%> sampler = pm.sampling.Sampler();
40%> fileList = sampler.findfile(ftype)
41%> fileList = sampler.findfile(ftype, [], [])
42%> fileList = sampler.findfile(ftype, [], silent)
43%> fileList = sampler.findfile(ftype, pattern, [])
44%> fileList = sampler.findfile(ftype, pattern, silent)
51%> \JoshuaOsborne, May 21 2024, 12:14 AM, University of Texas at Arlington<br>
52%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
53%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
54function fileList = findfile(self, ftype, pattern)
60 ftype = string(ftype);
61 suffix = ftype +
".txt";
63 if isempty(self.spec.outputFileName)
64 if pm.array.
len(self.input) ~= 0
66 % This extraction of ``outputFileName`` from the ``input`` file must be automated in future.
68 + "Apparently, you have set the ``input`` component of the sampler
object." + newline ...
69 + "Extract the value of the simulation specification ``outputFileName`` from this ``input``." + newline ...
70 + "Then, assign it to the simulation specification ``spec.outputFileName``." + newline ...
75 % warning ( newline ...
76 % + "The input simulation specification ``outputFileName`` is" + newline ...
77 % + "unset while the input argument ``pattern`` is missing." + newline ...
78 % + "Searching the current working directory:" + newline ...
80 % + pm.io.
tab +
string(pwd) + newline ...
82 % + "for potential ASCII " + ftype + " files..." + newline ...
86 pattern =
string(pwd());
88 pattern = self.spec.outputFileName;
95 %%%% Check if the input path is a full path to a file.
98 fileList =
string(pattern);
99 if ~self.silent && ~endsWith(pattern, suffix)
100 warning ( newline ...
101 + "The identified " + ftype + " file:" + newline ...
103 + pm.io.
tab + pattern + newline ...
105 + "does not end with the expected suffix """ + suffix + """." + newline ...
111 %%%% search for files matching the input pattern.
114 if isfolder(pattern) && ~endsWith(pattern, filesep)
115 % Ensure pattern is a directory with an explicit directory separator.
116 pattern = pattern + filesep;
118 if endsWith(pattern, "*")
119 dirList = dir(pattern);
121 dirList = dir(pattern + "*");
125 for ifile = 1 : length(dirList)
126 if contains(dirList(ifile).
name, suffix)
127 counter = counter + 1;
128 filePathModified = fullfile(
string(dirList(ifile).folder),
string(dirList(ifile).
name));
129 fileList = [fileList, filePathModified];
134 %%%% check if the input path is a url.
138 if pm.web.
isurl(pattern)
140 fileList = [
string(websave(fullfile(tempdir, pm.web.
basename(pattern)), pattern))];
142 warning ( newline ...
143 +
string(me.identifier) + " : " +
string(me.message) + newline ...
144 + "Failed to read data from the specified URL:" + newline ...
153 + "Failed to
detect any " + ftype + " files with the requested pattern:" + newline ...
155 + pm.io.
tab + pattern + newline ...
157 + "Specify an input ``pattern`` that either" + newline ...
159 + pm.io.
tab + "1. points to one or more " + ftype + " files, or," + newline ...
160 + pm.io.
tab + "2. represents the unique part of the names of a simulation." + newline ...
161 + pm.io.
tab + " This unique-
name is the common prefix in the names of" + newline ...
162 + pm.io.
tab + " the output files of a given sampling simulation." + newline ...
164 + "Note that binary files ending with the suffix ""*.bin"" cannot be currently parsed." + newline ...
166 if contains(ftype, "restart")
168 + "For restart files, you can set the simulation specification ``restartFileFormat`` to" + newline ...
170 + pm.io.
tab + "spec.restartFileFormat = ""ascii"";" + newline ...
172 + "to generate ASCII-format MATLAB-readable " + ftype + " files." ...
175 elseif contains(ftype, "chain")
177 + "For chain files, you can set the simulation specification ``chainFileFormat`` to" + newline ...
179 + pm.io.
tab + "spec.chainFileFormat = ""ascii"";" + newline ...
181 + "to generate ASCII-format MATLAB-readable " + ftype + " files." ...
190 disp(
string(length(fileList)) + " files were detected matching pattern: """ + pattern + """");
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
function basename(in url)
Return a scalar MATLAB string containing the basename part of an input url, defined as the segment of...
This is the base class for the ParaMonte sampler routines.
function detect(in vendor)
Return the MPI image count and current image ID (e.g., MPI rank + 1) and the MPI library name as it a...
function isurl(in url)
Return a scalar MATLAB logical that is true if and only if the input URL string exists in the world w...
function len(in obj)
Return a scalar MATLAB whole-number containing the length of the input scalar or vector object.
function tab()
Return a scalar MATLAB string containing 4 blank characters equivalent to a tab character.
function weblink(in silent)
Return a scalar MATLAB string containing the download weblink to latest ParaMonte MATLAB library vers...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...