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

Create a txt File

Create a txt File

Hi all,

how can I create a txt file, which can save important data. For example:

I have a simple model, which describes the projectile motion, like throwing a ball. It look something like this:
model wurf
  parameter Real m = 1;
  parameter Real v = 1;
  parameter Real alpha = 30;
  parameter Real h = 1;
  parameter Real g = 10;
  Real wegX; //X-Axe
  Real geschwindigkeitX(start = v*cos(alpha*3.14/180)); //speed X-Axe
  Real beschleunigungX; //accleration X-Axe
  Real wegY(start = h); //Y-Axe
  Real geschwindigkeitY(start = v*sin(alpha*3.14/180)); //speed Y-Axe
  Real beschleunigungY; //accleration Y-Axe
equation
  der(wegX) = geschwindigkeitX;
  der(geschwindigkeitX) = beschleunigungX;
  beschleunigungX = 0;
  der(wegY) = geschwindigkeitY;
  der(geschwindigkeitY) = beschleunigungY;
  beschleunigungY = -g; 
end wurf;

I would like to save the data of the Y-Axe (the hight of the ball) which depend on time in an text file. It should look something like this:

time     wegY(Y-Axe)
0          1
0,2       1.5
0,3       2

Can you guys help me? I am very new to OpenModelica.

Thanks in advance,
Marvin

Re: Create a txt File

Choose csv as the output format when you simulate:

Code:

marsj@marsj-Precision-5510:~/tmp$ ./wurf -override outputFormat=csv

LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
LOG_SUCCESS       | info    | The simulation finished successfully.
marsj@marsj-Precision-5510:~/tmp$ head -2 wurf_res.csv
"time","geschwindigkeitX","geschwindigkeitY","wegX","wegY","der(geschwindigkeitX)","der(geschwindigkeitY)","der(wegX)","der(wegY)","beschleunigungX"
0,0.8661580944054629,0.4997701026431026,0,1,0,-10,0.8661580944054629,0.4997701026431026,0

Re: Create a txt File

Yes I know that method, but I would like to save the data in a separate txt File. In this case I can build it as I would like.

sjoelund.se wrote:


Choose csv as the output format when you simulate:

Code:

marsj@marsj-Precision-5510:~/tmp$ ./wurf -override outputFormat=csv

LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
LOG_SUCCESS       | info    | The simulation finished successfully.
marsj@marsj-Precision-5510:~/tmp$ head -2 wurf_res.csv
"time","geschwindigkeitX","geschwindigkeitY","wegX","wegY","der(geschwindigkeitX)","der(geschwindigkeitY)","der(wegX)","der(wegY)","beschleunigungX"
0,0.8661580944054629,0.4997701026431026,0,1,0,-10,0.8661580944054629,0.4997701026431026,0

There are 0 guests and 0 other users also viewing this topic