ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
getEntryNML.m
Go to the documentation of this file.
1%> \brief
2%> Return a Fortran-namelist-compatible conversion of the input ``varval``.<br>
3%>
4%> \details
5%> This functionality is primarily used by the ParaMonte MATLAB internal
6%> routines to communicate information with Fortran shared libraries.<br>
7%> As such, it is of limited to most end users of the library.<br>
8%>
9%> \param[in] varname : The input scalar MATLAB string containing the label to assign
10%> to the namelist-converted value in the output ``entry``.<br>
11%> The specified value of ``varname`` will be trimmed
12%> (to remove leading and trailing blanks).<br>
13%> \param[in] varval : The input value to be converted to namelist-compatible value.<br>
14%> \param[in] vartype : See the documentation of the corresponding
15%> argument of [pm.introspection.istype()](@ref istype).<br>
16%> \param[in] maxlen : See the documentation of the corresponding
17%> argument of [pm.introspection.islenleq()](@ref islenleq).<br>
18%>
19%> \return
20%> ``entry`` : The output scalar MATLAB string containing the namelist-compatible
21%> conversion of the input value ``varval`` and the given ``varname``
22%> in the following format: ``varname=namelist-compatible-varval``.
23%>
24%> \interface{getEntryNML}
25%> \code{.m}
26%>
27%> entry = pm.fortran.getEntryNML(varname, varval, vartype, maxlen)
28%>
29%> \endcode
30%>
31%> \note
32%> If the input value is string, it will be quoted properly.<br>
33%> If the input ``varval`` is an array, its elements will be comma-separated.<br>
34%>
35%> \see
36%> [pm.introspection.verify](@ref verify)<br>
37%> [pm.introspection.verified](@ref verified)<br>
38%> [pm.introspection.islenleq](@ref islenleq)<br>
39%> [pm.introspection.istype](@ref istype)<br>
40%>
41%> \example{getEntryNML}
42%> \include{lineno} example/fortran/getEntryNML/main.m
43%> \output{getEntryNML}
44%> \include{lineno} example/fortran/getEntryNML/main.out.m
45%>
46%> \final{getEntryNML}
47%>
48%> \author
49%> \JoshuaOsborne, May 21 2024, 5:38 PM, University of Texas at Arlington<br>
50%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
51%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
52function entry = getEntryNML(varname, varval, vartype, maxlen)
53 varval = varval(:);
54 varvalen = numel(varval);
55 %varname = string(inputname(2));
56 varname = string(strtrim(varname));
57 if pm.introspection.verified(varval, vartype, maxlen)
58 entry = varname + "=";
59 delim = " ";
60 vartype = lower(vartype);
61 for i = 1 : varvalen
62 if isa(varval(i), "cell")
63 value = varval{i};
64 else
65 value = varval(i);
66 end
67 if strcmp(vartype, "string")
68 entry = entry + pm.fortran.quote(string(value)) + delim;
69 elseif strcmp(vartype, "integer")
70 if rem(value, 1) == 0
71 entry = entry + value + delim;
72 else
73 entry = entry + round(value) + delim;
74 end
75 elseif strcmp(vartype, "logical")
76 if value
77 entry = entry + ".true." + delim;
78 else
79 entry = entry + ".false." + delim;
80 end
81 elseif strcmp(vartype, "complex")
82 entry = entry + "(" + string(real(value)) + "," + string(imag(value)) + ")" + delim;
83 elseif strcmp(vartype, "real") || strcmpi(vartype, "float") || strcmpi(vartype, "single") || strcmpi(vartype, "double")
84 entry = entry + value + delim;
85 else
86 help("pm.fortran.getEntryNML");
87 disp("vartype");
88 disp( vartype );
89 error ( newline ...
90 + "Unrecognized input ``vartype`` value." + newline ...
91 + newline ...
92 );
93 end
94 end
95 else
96 disp(varname + " = ");
97 disp(varval);
98 error ( newline ...
99 + "The input " + varname + " specification value(s) displayed" + newline ...
100 + "above must be conformable to a MATLAB " + vartype + " type," + newline ...
101 + "with a maximum " + string(maxlen) + " number of elements." + newline ...
102 + "The specified value has the class:" + newline ...
103 + newline ...
104 + pm.io.tab() + "class(" + varname + ") = " + string(class(varval)) + newline ...
105 + newline ...
106 + "with size:" + newline ...
107 + newline ...
108 + pm.io.tab() + "size(" + varname + ") = [" + join(string(size(varval)), ", ") + "]" + newline ...
109 + newline ...
110 );
111 end
112end
function verify(in varval, in vartype, in maxlen, in varname)
Verify the type and number of elements of the input varval match the specified input vartype and maxl...
function getEntryNML(in varname, in varval, in vartype, in maxlen)
Return a Fortran-namelist-compatible conversion of the input varval.
function islenleq(in varval, in maxlen)
Return true if and only if the input varval has the specified maximum size maxlen,...
function istype(in varval, in vartype)
Return true if and only if the input varval conforms with the specified input type vartype,...
function quote(in str)
Return the input scalar MATLAB string as doubly quoted string such that the first and last character ...
function tab()
Return a scalar MATLAB string containing 4 blank characters equivalent to a tab character.
function verified(in varval, in vartype, in maxlen)
Return true if and only if the input varval conforms with the specified input type vartype and maximu...