ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
verify.m
Go to the documentation of this file.
1%> \brief
2%> Verify the type and number of elements of the input ``varval``
3%> match the specified input ``vartype`` and ``varsize``.<br>
4%> Otherwise, halt the program by calling the MATLAB
5%> intrinsic ``error()`` with an appropriate
6%> descriptive error message.<br>
7%>
8%> \details
9%> This function is merely a higher-level wrapper around
10%> the ParaMonte functionality [pm.introspection.istype()](@ref istype).<br>
11%> The goal is to offer a unified interface for argument verification and
12%> aborting the program with a suitable error message if
13%> the verification fails.<br>
14%>
15%> \param[in] varval : The input value to whose type and
16%> number of elements is to be verified.
17%> \param[in] vartype : See the documentation of the corresponding
18%> argument of [pm.introspection.istype()](@ref istype).
19%> \param[in] varsize : See the documentation of the corresponding
20%> argument of [pm.introspection.istype()](@ref istype).
21%> \param[in] varname : The input scalar MATLAB string containing the label to assign
22%> to the namelist-converted value in the output ``entry``.<br>
23%> The specified value of ``varname`` will be trimmed
24%> (to remove leading and trailing blanks) and used
25%> only for outputting an error message.<br>
26%> (**optional**, default = ``"value"``)
27%>
28%> \interface{verify}
29%> \code{.m}
30%>
31%> pm.introspection.verify(varval, vartype, varsize);
32%> pm.introspection.verify(varval, vartype, varsize, varname);
33%>
34%> \endcode
35%>
36%> \example{verify}
37%> \include{lineno} example/introspection/verify/main.m
38%> \output{verify}
39%> \include{lineno} example/introspection/verify/main.out.m
40%>
41%> \final{verify}
42%>
43%> \author
44%> \JoshuaOsborne, May 21 2024, 5:42 PM, University of Texas at Arlington<br>
45%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
46%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
47function verify(varval, vartype, varsize, varname)
48 if nargin < 4
49 varname = "value";
50 else
51 varname = string(strtrim(varname));
52 end
53 varval = varval(:);
54 if ~pm.introspection.istype(varval, vartype, varsize)
55 disp(varname + " = ");
56 disp(varval);
57 error ( newline ...
58 + "The input ``" + varname + "`` specification value(s) displayed" + newline ...
59 + "above must be conformable to a MATLAB " + vartype + " type," + newline ...
60 + "with a maximum " + string(varsize) + " number of elements." + newline ...
61 + "The specified value has the class:" + newline ...
62 + newline ...
63 + pm.io.tab + "class(" + varname + ") = " + string(class(varval)) + newline ...
64 + newline ...
65 + "with size:" + newline ...
66 + newline ...
67 + pm.io.tab + "size(" + varname + ") = [" + join(string(size(varval)), ", ") + "]" + newline ...
68 + newline ...
69 );
70 end
71end
function verify(in varval, in vartype, in varsize, in varname)
Verify the type and number of elements of the input varval match the specified input vartype and vars...
function istype(in varval, in vartype, in varsize)
Return true if and only if the input varval conforms with the specified input type vartype and the sp...