ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
Spinner.m
Go to the documentation of this file.
1%> \brief
2%> This is the base class for generating objects
3%> that can display the time spinner on the console.<br>
4%>
5%> \devnote
6%> The ``handle`` superclass is essential to allow
7%> object modification by the object methods.<br>
8%>
9%> \note
10%> See the documentation of the class constructor.<br>
11%>
12%> \note
13%> See below for information on the attributes (properties).<br>
14%>
15%> \note
16%> See below for information on the methods.<br>
17%>
18%> \final
19%>
20%> \author
21%> \JoshuaOsborne, May 21 2024, 5:39 AM, University of Texas at Arlington<br>
22%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
23%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
24classdef Spinner < pm.matlab.Handle
25
26 properties(Access = protected)
27 %>
28 %> ``tickmarks``
29 %>
30 %> The MATLAB ``char`` vector containing the set of
31 %> characters that represent the passage of time in the spinner.
32 %>
33 tickmarks = '|/-\';
34 end
35
36 properties(Hidden)
37 %>
38 %> ``tickCount``
39 %>
40 %> The MATLAB integer containing the length of ``tickmarks``.
41 %>
42 tickCount = 4;
43 %>
44 %> ``format``
45 %>
46 %> The MATLAB ``char`` vector containing the spinner display format.
47 %>
48 format = [repmat('\b', 1, 4 + 1), '%s'];
49 %>
50 %> ``clock``
51 %>
52 %> The scalar integer representing the index of the ``tickmarks`` attribute.
53 %>
54 clock = 0;
55 end
56
57
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
60 methods(Access = public)
61
62 %> \brief
63 %> Return a scalar object of class [pm.timing.Spinner](@ref Spinner).<br>
64 %>
65 %> \details
66 %> This is the constructor of the class [pm.timing.Spinner](@ref Spinner).<br>
67 %>
68 %> \param[in] tickmarks : The input MATLAB ``char`` vector containing the set of
69 %> characters that represent the passage of time in the spinner.<br>
70 %> (**optional**, default = ``'|/-\'``)
71 %>
72 %> \return
73 %> ``self`` : The output scalar object of class [pm.timing.Spinner](@ref Spinner).<br>
74 %>
75 %> \interface{Spinner}
76 %> \code{.m}
77 %>
78 %> self = pm.timing.Spinner()
79 %>
80 %> \endcode
81 %>
82 %> \example{Spinner}
83 %> \include{lineno} example/timing/Spinner/main.m
84 %> \output{Spinner}
85 %> \include{lineno} example/timing/Spinner/main.out.m
86 %>
87 %> \final{Spinner}
88 %>
89 %> \author
90 %> \JoshuaOsborne, May 21 2024, 5:43 AM, University of Texas at Arlington<br>
91 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
92 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
93 function self = Spinner()
94 self.tickmarks = '|/-\';
95 self.tickCount = length(self.tickmarks);
96 self.format = [repmat('\b', 1, self.tickCount + 3), '%s'];
97 self.clock = 0;
98 end
99
100 %> \brief
101 %> Rotate the tick mark of the spinner
102 %> and display the percentage value of the input fraction.<br>
103 %> This is a dynamic method of the class [pm.timing.Spinner](@ref Spinner).<br>
104 %>
105 %> \param[in] fraction : The input scalar MATLAB fractional real (``0 <= fraction <= 1``)
106 %> representing the fraction of work so far accomplished.<br>
107 %>
108 %> \interface{spin}
109 %> \code{.m}
110 %>
111 %> spinner = pm.timing.Spinner()
112 %> spinner.spin(fraction)
113 %>
114 %> \endcode
115 %>
116 %> \final{spin}
117 %>
118 %> \author
119 %> \JoshuaOsborne, May 21 2024, 5:45 AM, University of Texas at Arlington<br>
120 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
121 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
122 function spin(self, fraction)
123 if 0 < self.clock
124 if fraction < 1
125 self.clock = mod(self.clock, self.tickCount) + 1;
126 else
127 self.clock = 1;
128 end
129 fprintf(self.format, [self.tickmarks(self.clock), sprintf(' %3.0f', 100 * fraction), '% ']);
130 else
131 self.clock = self.clock + 1;
132 fprintf('%s', [self.tickmarks(self.clock), sprintf(' %3.0f', 100 * fraction), '% ']);
133 end
134 %if 1 <= fraction
135 % %fprintf('\b\b\b\b\b');
136 % fprintf('\n');
137 %end
138 end
139
140 end
141
142end
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
Property format
Definition: Spinner.m:53
function spin(in self, in fraction)
Rotate the tick mark of the spinner and display the percentage value of the input fraction....
Property clock
Definition: Spinner.m:60
Property tickCount
Definition: Spinner.m:46
function Spinner()
Return a scalar object of class pm.timing.Spinner.
Property tickmarks
Definition: Spinner.m:36