Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)

Forgot password? | Forgot username? | Register

Import external data from table

Import external data from table


i need to import meassurement data into a simulation and i dont realy get to do that. i have a dokument without any filename extention (works fine if added .csv for showing in excel) with  8760(1per hour for a year) data rows.

i found Modelica.Blocks.Tables.CombiTable1D in the examples but cant get it to function ... can anybody please give me some hints or direct me to a tutorial where i can see how it has to be done?

Next question would be, how to get these values in to the Variables at the right time and there comes Question 3: is it possible to run a simulation in timesteps of hours instead of seconds? I mean sure I can run it for 8760s and pretend it should be hours but would be cool if i could tell the Simulation to do hour steps.

Hope someone can help me out current/smile

Re: Import external data from table

If you are using a CSV-file, you need a version of MSL from the master branch as it has been very recently added: … 9b5d317e35

Otherwise, you need to convert your txt-file into one of the supported formats (read the documentation).

Re: Import external data from table

so you are telling me, that csv files are only possible with the latest devbuild?

and can you please link me the documentation where i can look up supported files?

Edited by: Pyrukar - Feb-22-21 07:42:08

Re: Import external data from table

The documentation is part of the library (you can browse it in OMEdit). You will need the latest OM nightly and also use the package manager to install the master version of the standard library:


installPackage(Complex, "4.0.0-master");
installPackage(ModelicaServices, "4.0.0-master");
installPackage(Modelica, "4.0.0-master");


>>> loadModel(Modelica, {"4.0.0-master"})


>>> getSourceFile(Modelica)
"/home/martin/.openmodelica/libraries/Modelica 4.0.0-master/"

>>> getSourceFile(ModelicaServices)
"/home/martin/.openmodelica/libraries/ModelicaServices 4.0.0-master/"

>>> getSourceFile(Complex)
"/home/martin/.openmodelica/libraries/Complex 4.0.0-master/"

Re: Import external data from table

okay, thanks for that,

but shouldnt Modelica.Blocks.Tables.CombiTable1D work? i mean sure i can make a txt ouf of my file and format it in the way that is needed acording to the documentation. But i dont understand the function and its not a example i could simply simulate to test it (Assertion triggered during translation: "tableOnFile = false and parameter table is an empty matrix")

also the Utility section looks promising. But the Modelica.Utilities.Examples.ReadRealMatrixFromFile doesnt run and besides that i dont have a Matlab file current/sad

Could i maybe use the Stream function to read strings from my external data an convert this into Reals ... could that work?

either way im downloading the nightly Build now ... maybe this new, promised function will work for me ( and maybe im able to understand it)

Re: Import external data from table

ModelicaTest has a lot of examples for tables if you want to see example code

Re: Import external data from table

Well a new questions:
you seem to use Linux for installing the Master version of the Library ... im on windows ... can you tell me where (probably on github?!) i can find that master library? i Found the the Test Library there but not the master.

and the Old one with the timesteps still isnt answered. Is there a good answer to?

Edited by: Pyrukar - Feb-23-21 07:32:41

Re: Import external data from table

The instructions are for Windows (using OMShell or OMEdit to access the command line). Otherwise, the libraries are here: … /OM/master

Re: Import external data from table

As for time steps, the unit in the specification is time as seconds. In OMEdit, you can change the displayed unit to be days. And you could create conversion variables 


Real timeInDays(unit="d") = time / 86400;

and use those in your code if necessary.

You could also pretend the unit is in hours instead of seconds, but then your model might not work correctly with other tools.

If it's the stopTime you are concerned with, I am sure that could be added to the GUI as an enhancement in the future.

Re: Import external data from table

Okay if i pretend my time steps are in hours i could say every timestep aka second is one hour and the plots can show the right unit (hour) instead of seconds? luckyly i dont have to integrate over time.

Re: Import external data from table

The plot would still say seconds, but you would know it is in hours. I'd recommend scaling it for proper models though

Re: Import external data from table

okay i now imported the new Modelica Master and found the Combi time Table and tried to feed it with values ... but i got an error message while compiling (simulating) : Error in line 11 when reading numeric data of matrix "Value(8760,3)" from file: ...

im aware that this is the last Value in the csv file (8670 lines and three colums if interpretet with excel) but i dont know where the Problem is.

EDIT: solved that mystery myself: i had german formating in place means , for decimal separation and ; for column separation ... needed . for decimal and , for column separation current/smile hint: csv = comma seperated values not semicolon separated values current/smile

Edited by: Pyrukar - Feb-23-21 13:57:13

Re: Import external data from table

Okay two more Problems to be solved:

1. My Model is still on version 3.2.3 and doesnt like to import a Model of version 4.0.0. This results in this warning and no integration done:
"Package Name" requested package Modelica of version 3.2.3. Modelica 4.0.0 is used instead which states that it is only compatible with a conversion script. OpenModelica currently does not support conversion scripts and will proceed with potential issues as a result.
how can i Fix that one without rewriting this?

2. I didnt get the OMshell comandline to work as i assumed so i until now worked with unloading the original Modelica Library and loading the new (loaded from github) 4.0.0. Master manually. but these steps need to be redone after each start of the OMedit. can someone please tell me how to automate this?

EDIT: Third question popping up right now ... i wanted to go around the questions 1 and 2 by using the standard Modelica Library and the txt format. There i get the error (wile compiling for simulation): The file name for a table (= "correctPath") is defined, but not the corresponding table name.

if i fill the parameter tableName with the matching stated name in the .txt it gives the same Error current/sad

Edited by: Pyrukar - Feb-23-21 14:55:49

Re: Import external data from table

1. You can't. You need to rewrite the code (or use the demo version of some Modelica tool that supports the conversion scripts, which will give you an updated model using MSL 4.0.0)

2. Go to Options | Libraries (I think) and change the version of Modelica you want to load by default (or don't load Modelica by default)

3. I'm unsure about this as I don't actually use tables myself current/big_smile

Re: Import external data from table

Okay now i updatet the whole Model to MSL 4.0.0 and still got problems:

If i use a model which contains only the model CombiTimeTable it works perfectly fine but if i integrate it to the complete model and use the y[:] to get the values only about 2000 of the 8760 Values are importet from my file. How could this happen and how to debug this?

Re: Import external data from table

in the mean time im one step further:

i now know that the simulation fails at a state and therefore the plot ends at that point.

the reason why it breaks is probably a If condition (x>y) makes trouble because x is nearly similar to y but i dont realy get why its a problem. x and y are Reals and the difference is already at the third decimal. This shouldnt give a identity and even a x>=y doesnt change anything current/sad what is the Problem there?

EDIT: Solved the Problem myself and it didnt have anything to do with the if condition but with some typo in the conditioned part current/smile

Edited by: Pyrukar - Feb-24-21 00:52:15
There are 0 guests and 0 other users also viewing this topic
You are here: