导入文本文件和Excel文件的步骤在Modelica中是什么?

huangapple go评论74阅读模式
英文:

Which are the steps to import a text file and an Excel file on Modelica?

问题

I want to use data for my model from two files: one with extension .txt and the other one with extension .csv. Then I want to have access to that specific data to process it as parameters. Do I have to use a function? What would be your take on this topic? Thank you!

PD: I'm using OpenModelica.

I've tried the ExternData library, but I think I don't get it quite right.

fileName = Modelica.Utilities.Files.loadResource("modelica:/Files/Examples/CSVReader/Data.csv")

英文:

I'm having a little trouble here. I want to use data for my model from two files: one with extension .txt and other one with extension .csv. Then I want to have access to that especific data to process it as parameters. Do I have to use a function? What would be your take on this topic? Thank you!

PD: I'm using OpenModelica.

I've tried the ExternData library but I think I don´t get it quite right.

fileName=Modelica.Utilities.Files.loadResource("modelica:/Files/Examples/CSVReader/Data.csv"),

答案1

得分: 3

我认为ExternData库是一个相当不错的选择。它支持多种文件类型,应该能满足您的需求,尽管问题在这方面有点模糊。

您有没有看过ExternData.Examples.CSVTest?那应该解释了该库的使用方式。基本上,它是一个两步过程:

  1. 您使用dataSource类来指定文件的路径以及文件类型。
  2. 然后通过dataSource中相应的函数来访问数据,例如dataSource.getRealArray2D(3, 2),其中的整数定义了要读取的矩阵的大小。

更多详情请参阅:https://ecp.ep.liu.se/index.php/modelica/article/view/189。

英文:

I think the ExternData library is a pretty good choice. It supports both file-types and should do what you want - although the question is a bit fuzzy in that regard.

Did you take a look at ExternData.Examples.CSVTest? That should explain how the library is used. Basically, it is a two-step process:

  1. You use the dataSource class to specify the path to the file as well as the file-type.
  2. Then you access the data via the respective functions (re)-declared in the dataSource, e.g. dataSource.getRealArray2D(3, 2) with the integers defining the size of the matrix that is read.

For more details: https://ecp.ep.liu.se/index.php/modelica/article/view/189.

huangapple
  • 本文由 发表于 2023年6月6日 16:00:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定