# Cannot return Result in OMJulia

**URL:** <https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [December 21, 2021, 1:04am UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406 "2021-12-21T01:04:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [December 21, 2021, 1:04am UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/1 "2021-12-21T01:04:12Z")

</div>

@arun3688 arun3688  
@JKRT RT  
@AnHeuermann AnHeuermann  
I am using OpenModelica and I am trying to read the output (i.e., `s` here). I tried several ways but could not succeed. Any idea to solve that?

```julia
using OMJulia
omc= OMJulia.OMCSession()
sendExpression(omc,"loadModel(Modelica)")
true
sendExpression(omc,"model a Real s; equation s=sin(10*time); end a;")
1-element Array{Symbol,1}:
 :a
sendExpression(omc,"simulate(a)")
L = sendExpression(omc,"readSimulationResult(a_res.mat)") # does not return anything
L = sendExpression(omc,"readSimulationResult(a_res)") # does not return anything
L = sendExpression(omc,"readSimulationResult(s)") # does not return anything

```

---

<div class="post-metadata">

**Author:** ![arun3688](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arun3688/32/27867_2.png) [@arun3688](https://discourse.julialang.org/u/arun3688)\
**Post date:** [December 21, 2021, 8:28am UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/2 "2021-12-21T08:28:26Z")

</div>

@Amro, You have to use `getErrorString()` API after every `sendExpression()` to see the error messages, And also the readSimulationResult() API requires two argument as input, first result file and second names of the variables as a list, So you should use something like below

sendExpression(omc, “readSimulationResult("a\_res.mat",{s})”)  
sendExpression(omc, “getErrorString()”)

Here are the list of API you can use and see their default and expected arguments. [OpenModelica.Scripting](https://build.openmodelica.org/Documentation/OpenModelica.Scripting.html)

---

<div class="post-metadata">

**Author:** ![AnHeuermann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anheuermann/32/27059_2.png) [@AnHeuermann](https://discourse.julialang.org/u/AnHeuermann)\
**Post date:** [December 22, 2021, 8:29am UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/4 "2021-12-22T08:29:51Z")

</div>

The error message tells you that Julia cannot handle the string

```julia
"readSimulationResult("path/to/a_res.mat"

```

Try escaping the quote signs `"` in the string:

```julia-repl
julia> OMJulia.sendExpression(omc, "readSimulationResult(\"a_res.mat\",{s})")
1-element Vector{Vector{Float64}}:
 [0.0, 0.01999866669333308, 0.03998933418663416, 0.0599640064794446, 0.0799146939691727, 0.09983341664682815, 0.1197122072889194, 0.1395431146442365, 0.159318206614246, 0.1790295734258242 … -0.4033931121687696, -0.4216117517033922, -0.4396617521587485, -0.4575358937753213, -0.4752270271347798, -0.4927280760196602, -0.5100320402437544, -0.527131998452086, -0.5440211108893698, -0.5440211108893698]

```

* * *

Alternatives to OpenModelica and `readSimulationResult()` would be to generate a CSV result file and use CSV.jl to read the data:

```julia-repl
sendExpression(omc,"simulate(a, outputFormat=\"csv\")")

```

I don’t know of a Julia package that can handle the mat file OpenModelica generates, at least MAT.jl is not working for them (no mat v4 support).

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [December 22, 2021, 5:18pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/5 "2021-12-22T17:18:34Z")

</div>

Thank you. Yes, now it works. I have tried the MAT.jl but it didnot work due to the not support of mat 4 generated by OpenModelica.

---

<div class="post-metadata">

**Author:** ![bilderbuchi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bilderbuchi/32/13562_2.png) [@bilderbuchi](https://discourse.julialang.org/u/bilderbuchi)\
**Post date:** [December 22, 2021, 6:39pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/7 "2021-12-22T18:39:56Z")

</div>

The usual way to achieve this in Modelica is by having k be of “parameter” variability. K can then be overridden/set for new simulations without having to recompile.

---

<div class="post-metadata">

**Author:** ![sjoelund](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sjoelund/32/32160_2.png) [@sjoelund](https://discourse.julialang.org/u/sjoelund)\
**Post date:** [December 22, 2021, 7:30pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/9 "2021-12-22T19:30:25Z")

</div>

[Scripting API — OpenModelica User's Guide v1.18.0-38-ga767f054d8 documentation](https://openmodelica.org/doc/OpenModelicaUsersGuide/1.18/scripting_api.html#simulation-parameter-sweep) is the corresponding code for OpenModelica mos-scripts. You can adapt it for Julia (easier on Linux since you need to set PATH variables on Windows if you call the executable within Julia).

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [December 22, 2021, 7:32pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/10 "2021-12-22T19:32:32Z")

</div>

Thank you very much. Can you send me the link for the documentation of setting the PATH variables on Windows if you call the executable within Julia

---

<div class="post-metadata">

**Author:** ![sjoelund](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sjoelund/32/32160_2.png) [@sjoelund](https://discourse.julialang.org/u/sjoelund)\
**Post date:** [December 22, 2021, 7:39pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/11 "2021-12-22T19:39:12Z")

</div>

There is no documentation as far as I know, and the Windows version of OpenModelica doesn’t run on my Windows work computer. Only the WSL version works… Maybe adding $OPENMODELICAHOME/bin is enough. I’m not sure.

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [December 22, 2021, 7:47pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/12 "2021-12-22T19:47:21Z")

</div>

Excuse me, I have to add `$OPENMODELICAHOME/bin` into the environment variables in windows or where specifically?

---

<div class="post-metadata">

**Author:** ![sjoelund](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sjoelund/32/32160_2.png) [@sjoelund](https://discourse.julialang.org/u/sjoelund)\
**Post date:** [December 22, 2021, 7:58pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/13 "2021-12-22T19:58:06Z")

</div>

You could do it inside of the Julia process or only setting it when calling the simulation executable. Note that you will need to expand OPENMODELICAHOME and it’s probably not set in the global environment unless you have an older installation. You can use [Scripting API — OpenModelica User's Guide v1.20.0-dev-270-g1a840876db documentation](https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/scripting_api.html#getinstallationdirectorypath) to query it

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [December 22, 2021, 8:02pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/14 "2021-12-22T20:02:05Z")

</div>

Thank you very much for explanations. I will read this part of documentation to become familiar with the issue here.

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [December 23, 2021, 8:43pm UTC](https://discourse.julialang.org/t/cannot-return-result-in-omjulia/73406/15 "2021-12-23T20:43:39Z")

</div>

@sjoelund  
Thank you for your explanations. I have read the documentation, but honestly I didn’t get it well.

> [@sjoelund](#):
>
> Maybe adding $OPENMODELICAHOME/bin is enough

Is it correct to add it in windows as below? or how can I do it withing julia?

 ![Screenshot 2021-12-23 155658](https://global.discourse-cdn.com/julialang/original/3X/2/0/2027738088ce78e6f8c33a324ba227f072801a09.png)

> [@sjoelund](#):
>
> You could do it inside of the Julia process or only setting it when calling the simulation executable

Could you please guide me here or give me example or link?

> [@sjoelund](#):
>
> Note that you will need to expand OPENMODELICAHOME and it’s probably not set in the global environment unless you have an older installation

Could you please guide me here or give me example or link?

> [@sjoelund](#):
>
> You can use [Scripting API — OpenModelica User’s Guide v1.19.0-dev-491-g8713a817d7e documentation](https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/scripting_api.html#getinstallationdirectorypath) to query it

it returns

> > getInstallationDirectoryPath()  
> > “C:/Program Files/OpenModelica1.18.0-64bit”
