Skip to content

Instantly share code, notes, and snippets.

@thorade
Last active November 18, 2015 16:21
Show Gist options
  • Save thorade/5aef81f0d233a95153fb to your computer and use it in GitHub Desktop.
Save thorade/5aef81f0d233a95153fb to your computer and use it in GitHub Desktop.
Access array elements from string argument in Modelica
package StackoverflowArray
record Dictionary "key value pair"
parameter String name "Unique name key";
parameter Real[:] c "coefficients";
end Dictionary;
function getIdx
input String key="B";
input Dictionary[2] dict={Dictionary(name="A", c={1,2,3}), Dictionary(name="B", c={4,5,6,7})};
output Integer idx;
protected
Boolean[:] b;
algorithm
b := {kv.name == key for kv in dict};
idx := Modelica.Math.BooleanVectors.firstTrueIndex(b);
end getIdx;
annotation (uses(Modelica(version="3.2.1")));
end StackoverflowArray;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment