Last active
November 18, 2015 16:21
-
-
Save thorade/5aef81f0d233a95153fb to your computer and use it in GitHub Desktop.
Access array elements from string argument in Modelica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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