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 %>
96 %> \param[in] silent : The input scalar MATLAB logical.<br>
97 %> If ``true``, all descriptive messages will be suppressed.<br>
98 %> Setting this option to ``false`` is particularly useful
99 %> in MPI-parallel simulations.<br>
100 %> (**optional**, default = ``false``)
101 %>
102 %> \return
103 %> ``self`` : The output scalar object of class [pm.io.FileContents](@ref FileContents).
104 %>
105 %> \interface{FileContents}
106 %> \code{.m}
107 %>
108 %> contents = pm.io.FileContents(file)
109 %> contents = pm.io.FileContents(file, [])
110 %> contents = pm.io.FileContents(file, silent)
111 %>
112 %> \endcode
113 %>
114 %> \final{FileContents}
115 %>
116 %> \author
117 %> \JoshuaOsborne, May 21 2024, 6:05 PM, University of Texas at Arlington<br>
118 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
119 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
120 function self = FileContents(file, silent)
121 if nargin < 2
122 silent = [];
123 end
124 if nargin < 1
125 file = [];
126 end
127 if ~isempty(silent)
128 self.silent = silent;
129 end
130 if ~isempty(file)
131 self.file = string(file);
132 end
133 if ~self.silent
134 disp("reading file: """ + self.file + """");
135 end
136 self.timer = pm.timing.Timer();
137 self.spinner = pm.timing.Spinner();
138 self.weblinks = pm.lib.weblinks();
139 end
140
141 end
142
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144
145 methods(Access = public, Hidden)
146
147 %> \brief
148 %> Display the input warning message about the line
149 %> number ``line`` of the file whose contents are read and return nothing.
150 %>
151 %> \details
152 %> This is a ``Hidden`` method of the class [pm.io.FileContents](@ref FileContents).<br>
153 %> The messaging within this routine occurs only if the ``silent`` attribute of the parent object
154 %> is set to ``false`` at the time of constructing the parent object of class [pm.io.FileContents](@ref FileContents).<br>
155 %>
156 %> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
157 %> \param[in] line : The input scalar MATLAB string or whole number,
158 %> representing the line number within the file about which the warning message should be printed.<br>
159 %> (**optional**, default = ``"UNKNOWN"``)
160 %> \param[in] msg : The input scalar MATLAB string containing a message to display on the MATLAB console.<br>
161 %> (**optional**, default = ``"done in " + sprintf("%.6f", string(self.timer.del())) + " seconds."``)
162 %>
163 %> \interface{warn}
164 %> \code{.m}
165 %>
166 %> fc = pm.io.FileContents(file)
167 %> fc.warn(line, msg)
168 %> fc.warn([], msg)
169 %> fc.warn([], [])
170 %> fc.warn()
171 %>
172 %> \endcode
173 %>
174 %> \final{warn}
175 %>
176 %> \author
177 %> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
178 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
179 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
180 function warn(self, line, msg)
181 if ~self.silent
182 if nargin < 3
183 msg = [];
184 end
185 if nargin < 2
186 line = [];
187 end
188 if ~isempty(msg)
189 msg = string(msg) + newline;
190 else
191 msg = "";
192 end
193 if ~isempty(line)
194 line = string(line);
195 else
196 line = "UNKNOWN";
197 end
198 warning ( newline ...
199 + "The structure of the input file:" + newline ...
200 + newline ...
201 + pm.io.tab + self.file + newline ...
202 + newline ...
203 + "appears compromised around line: " + line + newline ...
204 + msg ...
205 + "The file parsing will proceed with no guarantee of success." + newline ...
206 + newline ...
207 );
208 end
209 end
210
211 %> \brief
212 %> Display the input final message and return nothing.
213 %>
214 %> \details
215 %> This is a ``Hidden`` method of the class [pm.io.FileContents](@ref FileContents).<br>
216 %>
217 %> \param[inout] self : The **implicitly-passed** input/output argument representing the parent object of the method.<br>
218 %> \param[in] msg : The input scalar MATLAB string containing a
219 %> message to display on the MATLAB console.<br>
220 %> (**optional**, default = ``"done in " + sprintf("%.6f", string(self.timer.del())) + " seconds."``)
221 %>
222 %> \param[in] advance : The input scalar MATLAB ``logical``.<br>
223 %> If ``true``, an end of line character will be added at the end of the printed message.<br>
224 %> (**optional**, default = ``true``)
225 %>
226 %> \interface{checkpoint}
227 %> \code{.m}
228 %>
229 %> fc = pm.io.FileContents(file)
230 %> fc.checkpoint(msg, advance)
231 %> fc.checkpoint([], advance)
232 %> fc.checkpoint([], [])
233 %> fc.checkpoint(msg)
234 %> fc.checkpoint([])
235 %> fc.checkpoint()
236 %>
237 %> \endcode
238 %>
239 %> \final{checkpoint}
240 %>
241 %> \author
242 %> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
243 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
244 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
245 function checkpoint(self, msg, advance)
246 if ~self.silent
247 if nargin < 3
248 advance = [];
249 end
250 if nargin < 2
251 msg = [];
252 end
253 if isempty(advance)
254 advance = true;
255 end
256 if isempty(msg)
257 msg = "done in " + sprintf("%.6f", string(self.timer.del())) + " seconds.";
258 end
259 if advance
260 disp(msg);
261 else
262 fprintf(msg);
263 end
264 end
265 end
266
267 %%> \brief
268 %%> Return a copy of the specified ``field`` (component)
269 %%> of the parent object of class [pm.io.FileContents](@ref FileContents).
270 %%>
271 %%> \details
272 %%> This method is an unfortunate result of the lack references in MATLAB.<br>
273 %%> The output of this method is used by the visualization methods of
274 %%> this class to repeatedly sync the internal copy of ``df`` with
275 %%> the original ``df`` component of the parent object.
276 %%>
277 %%> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
278 %%> \param[in] field : The input scalar MATLAB string containing the
279 %%> name of a field (component/attribute) of the parent
280 %%> object whose value will have to be returned.<br>
281 %%>
282 %%> \return
283 %%> ``val`` : The output object containing the value of the
284 %%> specified ``field`` of the parent object.<br>
285 %%>
286 %%> \interface{getVal}
287 %%> \code{.m}
288 %%>
289 %%> fc = pm.io.FileContents(field)
290 %%> val = fc.getVal(field)
291 %%>
292 %%> \endcode
293 %%>
294 %%> \final{getVal}
295 %%>
296 %%> \author
297 %%> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
298 %%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
299 %%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
300 %function val = getVal(self, field)
301 % val = self.(field);
302 %end
303
304 end
305
306end
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...