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 : The scalar MATLAB logical (Boolean) indicator which is ``false`` by default.<br>
31 %> If it is set to ``true``, it will silence all output postprocessing messages.<br>
32 %>
33 silent = false;
34 %>
35 %> file : The scalar MATLAB string containing the path to the file whose contents are read.
36 %>
37 file = "";
38 end
39
40 properties(Hidden)
42 spinner;
43 timer;
44 end
45
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 methods(Access = public)
51 %> \brief
52 %> Return a scalar object of class [pm.io.FileContents](@ref FileContents).
53 %>
54 %> \details
55 %> This is the constructor of the class [pm.io.FileContents](@ref FileContents).<br>
56 %> It merely serves as the blueprint for the IO subclasses
57 %> accessible to the end users.<br>
58 %>
59 %> \param[in] file : The input scalar MATLAB string
60 %> containing the path to an external file.
61 %>
62 %> \param[in] silent : The input scalar MATLAB logical.<br>
63 %> If ``true``, all descriptive messages will be suppressed.<br>
64 %> Setting this option to ``false`` is particularly useful
65 %> in MPI-parallel simulations.<br>
66 %> (**optional**, default = ``false``)
67 %>
68 %> \return
69 %> ``self`` : The output scalar object of class [pm.io.FileContents](@ref FileContents).
70 %>
71 %> \interface{FileContents}
72 %> \code{.m}
73 %>
74 %> contents = pm.io.FileContents(file)
75 %> contents = pm.io.FileContents(file, [])
76 %> contents = pm.io.FileContents(file, silent)
77 %>
78 %> \endcode
79 %>
80 %> \final{FileContents}
81 %>
82 %> \author
83 %> \JoshuaOsborne, May 21 2024, 6:05 PM, University of Texas at Arlington<br>
84 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
85 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
86 function self = FileContents(file, silent)
87 if nargin < 2
88 silent = [];
89 end
90 if nargin < 1
91 file = [];
92 end
93 if ~isempty(silent)
94 self.silent = silent;
95 end
96 if ~isempty(file)
97 self.file = string(file);
98 end
99 if ~self.silent
100 disp("reading file: """ + self.file + """");
101 end
102 self.timer = pm.timing.Timer();
103 self.spinner = pm.timing.Spinner();
104 self.weblinks = pm.lib.weblinks();
105 end
106
107 end
108
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
111 methods(Access = public, Hidden)
112
113 %> \brief
114 %> Display the input warning message about the line
115 %> number ``line`` of the file whose contents are read and return nothing.
116 %>
117 %> \details
118 %> This is a ``Hidden`` method of the class [pm.io.FileContents](@ref FileContents).<br>
119 %> The messaging within this routine occurs only if the ``silent`` attribute of the parent object
120 %> is set to ``false`` at the time of constructing the parent object of class [pm.io.FileContents](@ref FileContents).<br>
121 %>
122 %> \param[in] line : The input scalar MATLAB string or whole number,
123 %> representing the line number within the file about which the warning message should be printed.<br>
124 %> (**optional**, default = ``"UNKNOWN"``)
125 %>
126 %> \param[in] msg : The input scalar MATLAB string containing a message to display on the MATLAB console.<br>
127 %> (**optional**, default = ``"done in " + sprintf("%.6f", string(self.timer.del())) + " seconds."``)
128 %>
129 %> \interface{warn}
130 %> \code{.m}
131 %>
132 %> fc = pm.io.FileContents(file)
133 %> fc.warn(line, msg)
134 %> fc.warn([], msg)
135 %> fc.warn([], [])
136 %> fc.warn()
137 %>
138 %> \endcode
139 %>
140 %> \final{warn}
141 %>
142 %> \author
143 %> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
144 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
145 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
146 function warn(self, line, msg)
147 if ~self.silent
148 if nargin < 3
149 msg = [];
150 end
151 if nargin < 2
152 line = [];
153 end
154 if ~isempty(msg)
155 msg = string(msg) + newline;
156 else
157 msg = "";
158 end
159 if ~isempty(line)
160 line = string(line);
161 else
162 line = "UNKNOWN";
163 end
164 warning ( newline ...
165 + "The structure of the input file:" + newline ...
166 + newline ...
167 + pm.io.tab + self.file + newline ...
168 + newline ...
169 + "appears compromised around line: " + line + newline ...
170 + msg ...
171 + "The file parsing will proceed with no guarantee of success." + newline ...
172 + newline ...
173 );
174 end
175 end
176
177 %> \brief
178 %> Display the input final message and return nothing.
179 %>
180 %> \details
181 %> This is a ``Hidden`` method of the class [pm.io.FileContents](@ref FileContents).<br>
182 %>
183 %> \param[in] msg : The input scalar MATLAB string containing a
184 %> message to display on the MATLAB console.<br>
185 %> (**optional**, default = ``"done in " + sprintf("%.6f", string(self.timer.del())) + " seconds."``)
186 %>
187 %> \param[in] advance : The input scalar MATLAB ``logical``.<br>
188 %> If ``true``, an end of line character will be added at the end of the printed message.<br>
189 %> (**optional**, default = ``true``)
190 %>
191 %> \interface{checkpoint}
192 %> \code{.m}
193 %>
194 %> fc = pm.io.FileContents(file)
195 %> fc.checkpoint(msg, advance)
196 %> fc.checkpoint([], advance)
197 %> fc.checkpoint([], [])
198 %> fc.checkpoint(msg)
199 %> fc.checkpoint([])
200 %> fc.checkpoint()
201 %>
202 %> \endcode
203 %>
204 %> \final{checkpoint}
205 %>
206 %> \author
207 %> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
208 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
209 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
210 function checkpoint(self, msg, advance)
211 if ~self.silent
212 if nargin < 3
213 advance = [];
214 end
215 if nargin < 2
216 msg = [];
217 end
218 if isempty(advance)
219 advance = true;
220 end
221 if isempty(msg)
222 msg = "done in " + sprintf("%.6f", string(self.timer.del())) + " seconds.";
223 end
224 if advance
225 disp(msg);
226 else
227 fprintf(msg);
228 end
229 end
230 end
231
232 %%> \brief
233 %%> Return a copy of the specified ``field`` (component)
234 %%> of the parent object of class [pm.io.FileContents](@ref FileContents).
235 %%>
236 %%> \details
237 %%> This method is an unfortunate result of the lack references in MATLAB.<br>
238 %%> The output of this method is used by the visualization methods of
239 %%> this class to repeatedly sync the internal copy of ``df`` with
240 %%> the original ``df`` component of the parent object.
241 %%>
242 %%> \param[in] field : The input scalar MATLAB string containing the
243 %%> name of a field (component/attribute) of the parent
244 %%> object whose value will have to be returned.<br>
245 %%>
246 %%> \return
247 %%> ``val`` : The output object containing the value of the
248 %%> specified ``field`` of the parent object.<br>
249 %%>
250 %%> \interface{getVal}
251 %%> \code{.m}
252 %%>
253 %%> fc = pm.io.FileContents(field)
254 %%> val = fc.getVal(field)
255 %%>
256 %%> \endcode
257 %%>
258 %%> \final{getVal}
259 %%>
260 %%> \author
261 %%> \JoshuaOsborne, May 21 2024, 6:07 PM, University of Texas at Arlington<br>
262 %%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
263 %%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
264 %function val = getVal(self, field)
265 % val = self.(field);
266 %end
267
268 end
269
270end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
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:41
Property silent
Definition: FileContents.m:36
Property spinner
Definition: FileContents.m:48
Property timer
Definition: FileContents.m:50
Property weblinks
Definition: FileContents.m:46
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 fields)
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...