ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
FileContents.m
Go to the documentation of this file.
1%> \brief
2%> This is the base class for generating objects
3%> that contain the contents of a given file.<br>
4%>
5%> \details
6%> This class is meant to be primarily internally used
7%> by the ParaMonte library routines (e.g., samplers).<br>
8%>
9%> \devnote
10%> The ``handle`` superclass of this class
11%> is critical for the class functionality.<br>
12%> See the documentation of the class constructor.<br>
13%>
14%> \note
15%> See below for information on class attributes (properties).<br>
16%>
17%> \note
18%> See below for information on the methods.<br>
19%>
20%> \final{FileContents}
21%>
22%> \author
23%> \JoshuaOsborne, May 21 2024, 6:03 PM, University of Texas at Arlington<br>
24%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
25%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
26classdef FileContents < pm.matlab.Handle
27
28 properties(Access = public)
29 %>
30 %> ``silent``
31 %>
32 %> The scalar MATLAB logical (Boolean) indicator which is ``false`` by default.<br>
33 %> If it is set to ``true``, it will silence all output postprocessing messages.<br>
34 %>
35 silent = false;
36 %>
37 %> ``file``
38 %>
39 %> The scalar MATLAB string containing the path to the file whose contents are read.<br>
40 %>
41 file = "";
42 end
43
44 properties(Hidden)
45 %>
46 %> ``weblinks``
47 %>
48 %> The scalar ``Hidden`` MATLAB ``struct`` returned by [pm.lib.weblinks](@ref weblinks)
49 %> used internally for displaying the ParaMonte library web links.<br>
50 %>
51 %> \warning
52 %> This is an internal ``Hidden`` class attribute
53 %> that is inaccessible to the end users.<br>
54 %>
56 %>
57 %> ``spinner``
58 %>
59 %> The scalar ``Hidden`` MATLAB object of class [pm.timing.Spinner](@ref Spinner)
60 %> used internally for displaying the progress in file contents processing.<br>
61 %>
62 %> \warning
63 %> This is an internal ``Hidden`` class attribute
64 %> that is inaccessible to the end users.<br>
65 %>
66 spinner;
67 %>
68 %> ``timer``
69 %>
70 %> The scalar ``Hidden`` MATLAB object of class [pm.timing.Timer](@ref Timer)
71 %> used internally for displaying the timing of the progress in file contents processing.<br>
72 %>
73 %> \warning
74 %> This is an internal ``Hidden`` class attribute
75 %> that is inaccessible to the end users.<br>
76 %>
77 timer;
78 end
79
80
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 methods(Access = public)
85 %> \brief
86 %> Return a scalar object of class [pm.io.FileContents](@ref FileContents).
87 %>
88 %> \details
89 %> This is the constructor of the class [pm.io.FileContents](@ref FileContents).<br>
90 %> It merely serves as the blueprint for the IO subclasses
91 %> accessible to the end users.<br>
92 %>
93 %> \param[in] file : The input scalar MATLAB string
94 %> containing the path to an external file.
95 %> \param[in] silent : The input scalar MATLAB logical.<br>
96 %> If ``true``, all descriptive messages will be suppressed.<br>
97 %> Setting this option to ``false`` is particularly
98 %> useful in MPI-parallel simulations.<br>
99 %> (**optional**, default = ``false``)
100 %>
101 %> \return
102 %> ``self`` : The output scalar object of class [pm.io.FileContents](@ref FileContents).
103 %>
104 %> \interface{FileContents}
105 %> \code{.m}
106 %>
107 %> contents = pm.io.FileContents(file)
108 %> contents = pm.io.FileContents(file, [])
109 %> contents = pm.io.FileContents(file, silent)
110 %>
111 %> \endcode
112 %>
113 %> \final{FileContents}
114 %>
115 %> \author
116 %> \JoshuaOsborne, May 21 2024, 6:05 PM, University of Texas at Arlington<br>
117 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
118 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
119 function self = FileContents(file, silent)
120 if nargin < 2
121 silent = [];
122 end
123 if nargin < 1
124 file = [];
125 end
126 if ~isempty(silent)
127 self.silent = silent;
128 end
129 if ~isempty(file)
130 self.file = string(file);
131 end
132 if ~self.silent
133 disp("reading file: """ + self.file + """");
134 end
135 self.timer = pm.timing.Timer();
136 self.spinner = pm.timing.Spinner();
137 self.weblinks = pm.lib.weblinks();
138 end
139
140 end
141
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143
144 methods(Access = public, Hidden)
145
146 %> \brief
147 %> Display the input warning message about the line
148 %> number ``line`` of the file whose contents are read and return nothing.
149 %>
150 %> \details
151 %> This is a ``Hidden`` method of the class [pm.io.FileContents](@ref FileContents).<br>
152 %> The messaging within this routine occurs only if the ``silent`` attribute of the parent object
153 %> is set to ``false`` at the time of constructing the parent object of class [pm.io.FileContents](@ref FileContents).<br>
154 %>
155 %> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
156 %> \param[in] line : The input scalar MATLAB string or whole number,
157 %> representing the line number within the file about which the warning message should be printed.<br>
158 %> (**optional**, default = ``"UNKNOWN"``)
159 %> \param[in] msg : The input scalar MATLAB string containing a message to display on the MATLAB console.<br>
160 %> (**optional**, default = ``"done in " + sprintf("%.6f", string(self.timer.del())) + " seconds."``)
161 %>
162 %> \interface{warn}
163 %> \code{.m}
164 %>
165 %> fc = pm.io.FileContents(file)
166 %> fc.warn(line, msg)
167 %> fc.warn([], msg)
168 %> fc.warn([], [])
169 %> fc.warn()
170 %>
171 %> \endcode
172 %>
173 %> \final{warn}
174 %>
175 %> \author
176 %> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
177 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
178 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
179 function warn(self, line, msg)
180 if ~self.silent
181 if nargin < 3
182 msg = [];
183 end
184 if nargin < 2
185 line = [];
186 end
187 if ~isempty(msg)
188 msg = string(msg) + newline;
189 else
190 msg = "";
191 end
192 if ~isempty(line)
193 line = string(line);
194 else
195 line = "UNKNOWN";
196 end
197 warning ( newline ...
198 + "The structure of the input file:" + newline ...
199 + newline ...
200 + pm.io.tab + self.file + newline ...
201 + newline ...
202 + "appears compromised around line: " + line + newline ...
203 + msg ...
204 + "The file parsing will proceed with no guarantee of success." + newline ...
205 + newline ...
206 );
207 end
208 end
209
210 %> \brief
211 %> Display the input final message and return nothing.
212 %>
213 %> \details
214 %> This is a ``Hidden`` method of the class [pm.io.FileContents](@ref FileContents).<br>
215 %>
216 %> \param[inout] self : The **implicitly-passed** input/output argument representing the parent object of the method.<br>
217 %> \param[in] msg : The input scalar MATLAB string containing a
218 %> message to display on the MATLAB console.<br>
219 %> (**optional**, default = ``"done in " + sprintf("%.6f", string(self.timer.del())) + " seconds."``)
220 %> \param[in] advance : The input scalar MATLAB ``logical``.<br>
221 %> If ``true``, an end of line character will be added at the end of the printed message.<br>
222 %> (**optional**, default = ``true``)
223 %>
224 %> \interface{checkpoint}
225 %> \code{.m}
226 %>
227 %> fc = pm.io.FileContents(file)
228 %> fc.checkpoint(msg, advance)
229 %> fc.checkpoint([], advance)
230 %> fc.checkpoint([], [])
231 %> fc.checkpoint(msg)
232 %> fc.checkpoint([])
233 %> fc.checkpoint()
234 %>
235 %> \endcode
236 %>
237 %> \final{checkpoint}
238 %>
239 %> \author
240 %> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
241 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
242 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
243 function checkpoint(self, msg, advance)
244 if ~self.silent
245 if nargin < 3
246 advance = [];
247 end
248 if nargin < 2
249 msg = [];
250 end
251 if isempty(advance)
252 advance = true;
253 end
254 if isempty(msg)
255 msg = "done in " + sprintf("%.6f", string(self.timer.del())) + " seconds.";
256 end
257 if advance
258 disp(msg);
259 else
260 fprintf(msg);
261 end
262 end
263 end
264
265 %%> \brief
266 %%> Return a copy of the specified ``field`` (component)
267 %%> of the parent object of class [pm.io.FileContents](@ref FileContents).
268 %%>
269 %%> \details
270 %%> This method is an unfortunate result of the lack references in MATLAB.<br>
271 %%> The output of this method is used by the visualization methods of
272 %%> this class to repeatedly sync the internal copy of ``df`` with
273 %%> the original ``df`` component of the parent object.
274 %%>
275 %%> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
276 %%> \param[in] field : The input scalar MATLAB string containing the
277 %%> name of a field (component/attribute) of the parent
278 %%> object whose value will have to be returned.<br>
279 %%>
280 %%> \return
281 %%> ``val`` : The output object containing the value of the
282 %%> specified ``field`` of the parent object.<br>
283 %%>
284 %%> \interface{getVal}
285 %%> \code{.m}
286 %%>
287 %%> fc = pm.io.FileContents(field)
288 %%> val = fc.getVal(field)
289 %%>
290 %%> \endcode
291 %%>
292 %%> \final{getVal}
293 %%>
294 %%> \author
295 %%> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
296 %%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
297 %%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
298 %function val = getVal(self, field)
299 % val = self.(field);
300 %end
301
302 end
303
304end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
This is the base class for generating objects that contain the contents of a given file.
Definition: FileContents.m:27
function checkpoint(in self, in msg, in advance)
Display the input final message and return nothing.
Property file
Definition: FileContents.m:45
Property silent
Definition: FileContents.m:38
Property spinner
Definition: FileContents.m:72
Property timer
Definition: FileContents.m:84
Property weblinks
Definition: FileContents.m:60
function FileContents(in file, in silent)
Return a scalar object of class pm.io.FileContents.
function warn(in self, in line, in msg)
Display the input warning message about the line number line of the file whose contents are read and ...
This is the base class for generating subclass of MATLAB handle superclass whose annoying methods are...
Definition: Handle.m:24
This is the base class for generating objects that can display the time spinner on the console.
Definition: Spinner.m:25
This is the base class for generating objects that can time interval consecutively.
Definition: Timer.m:31
function copy(in from, in to, in field, in exclude)
Copy the contents of the struct/object from to the struct/object to recursively and without destroyin...
function lib()
Return a scalar MATLAB string containing the path to the lib directory of the ParaMonte library packa...
function parallel()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function tab()
Return a scalar MATLAB string containing 4 blank characters equivalent to a tab character.
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...