Skip to content

Instantly share code, notes, and snippets.

@paulkernstock
Created November 18, 2015 14:46
Show Gist options
  • Save paulkernstock/8ccbe87f3c7d8a9fb349 to your computer and use it in GitHub Desktop.
Save paulkernstock/8ccbe87f3c7d8a9fb349 to your computer and use it in GitHub Desktop.
Reading out coefficients, dictionary style
record Dictionary "Dictionary record for getting values using name lookup"
parameter String name "Unique name used as identifier";
parameter Real c[:] "Coefficients";
end Dictionary;
record R
constant String name;
end R;
function FooFunction
input R r annotation(choicesAllMatching=true);
output Real[3] o;
protected
parameter Dictionary[2] dict={Dictionary(name="A",c={1,2,3}),Dictionary(name="B",c={4,5,6})};
Boolean[:] b;
Integer index;
algorithm
b := {i.name == r.name for i in dict};
index :=Modelica.Math.BooleanVectors.firstTrueIndex(b);
o := dict[index].c;
end FooFunction;
@thorade
Copy link

thorade commented Nov 18, 2015

If you change the name and extension from gistfile1.txt to example.mo you will get syntax highlighting.

@thorade
Copy link

thorade commented Nov 18, 2015

On stackoverflow, you posted the HTTPS clone URL:
https://gist.github.com/8ccbe87f3c7d8a9fb349.git
That address will work for cloning! Every gist is also a git repository (and it has revisions).

If you want to link to this page here, just copy the URL from the address bar:
https://gist.github.com/8ccbe87f3c7d8a9fb349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment