This function returns the symbol (symbol),
stoichiometric coefficient (n), and electrical charge
(z) associated with an element as it appears in a chemical
formula (formula). After any initial whitespace in the
formula string, which is ignored, the symbol must
begin with a letter and may continue with lowercase letters. The
symbol may be followed by a positive integer and then a charge
number (both independently optional). If present, the charge number
must begin with "+" or "-" and may be followed by optional digits.
The remainder output gives the remainder of the
formula string after the symbol, coefficient, and
charge have been extracted.
If the coefficient is not explicitly given, then it is assumed
to be one. If the charge number is not given, then it is assumed to
be zero. A "+" or "-" without following digits is interpreted as a
charge of +1 or -1, respectively. If there is an error, then
symbol will be an empty string.
Example:
(symbol, n, z, remainder) = readElement("Hg2+2")
returns symbol="Hg", n=2,
z=2, and remainder="".
function readElement
extends Modelica.Icons.Function;
input String formula "Chemical formula";
output String symbol "Name of element (empty if error)";
output Integer n "Stoichiometric coefficient" annotation(
Dialog(__Dymola_label = "<html><i>n</i></html>"));
output Integer z "Charge number" annotation(
Dialog(__Dymola_label = "<html><i>z</i></html>"));
output String remainder "Remainder of the chemical formula";
end readElement;