2%> Return a Fortran-namelist-compatible conversion of the input ``varval``.<br>
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>
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.
14%> \param[in] vartype : See the documentation of the corresponding
15%> argument of [pm.introspection.istype()](@ref
istype).
16%> \param[in] varsize : See the documentation of the corresponding
17%> argument of [pm.introspection.istype()](@ref
istype).
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``.
27%> entry = pm.introspection.getEntryNML(varname, varval, vartype, varsize)
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>
36%> \include{lineno} example/introspection/
getEntryNML/main.m
38%> \include{lineno} example/introspection/
getEntryNML/main.out.m
43%> \JoshuaOsborne, May 21 2024, 5:38 PM, University of Texas at Arlington<br>
44%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
45%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
46function entry =
getEntryNML(varname, varval, vartype, varsize)
48 varvalen = numel(varval);
49 %varname = string(inputname(2));
50 varname = string(strtrim(varname));
51 if pm.introspection.istype(varval, vartype, varsize)
52 entry = varname +
"=";
54 vartype = lower(vartype);
56 if isa(varval(i),
"cell")
61 if strcmp(vartype,
"string")
62 entry = entry + pm.str.
quote(
string(value)) + delim;
63 elseif strcmp(vartype, "integer")
65 entry = entry + value + delim;
67 entry = entry + round(value) + delim;
69 elseif strcmp(vartype, "logical")
71 entry = entry + ".true." + delim;
73 entry = entry + ".false." + delim;
75 elseif strcmp(vartype, "complex")
76 entry = entry + "(" +
string(real(value)) + "," +
string(imag(value)) + ")" + delim;
77 elseif strcmp(vartype, "real") || strcmpi(vartype, "
float") || strcmpi(vartype, "single") || strcmpi(vartype, "
double")
78 entry = entry + value + delim;
84 + "Unrecognized input ``vartype`` value." + newline ...
90 disp(varname + " = ");
93 + "The input " + varname + " specification value(s) displayed" + newline ...
94 + "above must be conformable to a MATLAB " + vartype + " type," + newline ...
95 + "with a maximum " +
string(varsize) + " number of elements." + newline ...
96 + "The specified value has the class:" + newline ...
98 + " class(" + varname + ") = " +
string(class(varval)) + newline ...
100 + "with size:" + newline ...
102 + " size(" + varname + ") = [" + join(
string(size(varval)), ", ") + "]" + newline ...
function getEntryNML(in varname, in varval, in vartype, in varsize)
Return a Fortran-namelist-compatible conversion of the input varval.
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...
function quote(in str)
Return the input scalar MATLAB string as doubly quoted string such that the first and last character ...