updateEquation(MyModel, "x = 1", "x = 2")
updateEquation takes two equations, given as strings that are parsed as Modelica equations, and replaces an equation in the given class that matches the first equation with the second. If
newEqis an empty string, then the matching equation is removed instead of replaced.
matchAllis true, then updateEquation replaces all equations that matches. Otherwise it only replaces the first matching equation.
matchShallowis true, then equations are only matched shallowly, ignoring any nested equations. I.e.
updateEquation(M, "if b then end if", ...)will replace any if-equation that matches
if b then, regardless of what equations the if-equation contains. If
matchShallowis false, then the equations must match recursively.
matchDescriptionis true, then the description strings and annotations of the equations must match. Otherwise these are ignored when matching equations.
mergeDescriptionis true, then the description string and/or annotations of the replaced equation are copied to the new equation if these are missing on the new equation. This requires that
matchDescriptionis false, otherwise there will be nothing to merge since the equations must have the same description to match. If
mergeDescriptionis false, then the new equation overwrites the old completely, including description strings and annotations.
function updateEquation input TypeName className "The name of the class"; input String oldEq "The equation to replace"; input String newEq "The equation to replace with"; input Boolean matchAll = false "Update all matching equations if true, otherwise only the first matching"; input Boolean matchShallow = true "Ignore nested equations if true, otherwise match the equations recursively"; input Boolean matchDescription = false "Match description strings/annotations if true, otherwise ignore them"; input Boolean mergeDescription = false "Keep description string/annotations from the old equation if true"; output Boolean success "true if any equation was updated, otherwise false"; end updateEquation;