Skip to content

Commit

Permalink
Add read support of 1D and 2D real arrays from SSV 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Jan 3, 2025
1 parent ceed381 commit 2f3c7b8
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 10 deletions.
8 changes: 5 additions & 3 deletions ExternData/Examples/package.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// CP: 65001
/* package.mo - Modelica Examples library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Excel XLS/XLSX or XML files
/* package.mo - Modelica Examples library for data I/O of CSV, INI, JSON, MATLAB MAT, SSV, TIR, Excel XLS/XLSX or XML files
*
* Copyright (C) 2015-2025, Thomas Beutlich
* All rights reserved.
Expand Down Expand Up @@ -61,13 +61,15 @@ package Examples "Test examples"

model SSVTest "SSV file read test"
extends Modelica.Icons.Example;
inner parameter ExternData.SSVFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.ssv")) "SSV file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner parameter ExternData.SSVFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test_v2.ssv")) "SSV file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal("gain.k")) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Sources.ContinuousClock clock annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
final parameter Integer m = dataSource.getArrayRows2D("table1") "Number of rows in 2D array";
Modelica.Blocks.Sources.TimeTable timeTable(table=dataSource.getRealArray2D("table1", 3, 2)) annotation(Placement(transformation(extent={{-50,30},{-30,50}})));
equation
connect(clock.y,gain1.u) annotation(Line(points={{-29,70},{-17,70}}, color={0,0,127}));
annotation(experiment(StopTime=1),
Documentation(info="<html><p>This example model reads the gain parameter from the corresponding node of the SSV file <a href=\"modelica://ExternData/Resources/Examples/test.ssv\">test.ssv</a>. For gain1 the gain parameter is read as Real value using the function <a href=\"modelica://ExternData.SSVFile.getReal\">ExternData.SSVFile.getReal</a>. The read parameter is assigned by a parameter binding to the appropriate model parameter.</p></html>"));
Documentation(info="<html><p>This example model reads the gain parameter from the corresponding node of the SSV file <a href=\"modelica://ExternData/Resources/Examples/test_v2.ssv\">test_v2.ssv</a>. For gain1 the gain parameter is read as Real value using the function <a href=\"modelica://ExternData.SSVFile.getReal\">ExternData.SSVFile.getReal</a>. For timeTable the table parameter is read as Real array of dimension 3x2 by function <a href=\"modelica://ExternData.SSVFile.getRealArray2D\">ExternData.SSVFile.getRealArray2D</a>. The read parameters are assigned by parameter bindings to the appropriate model parameters.</p></html>"));
end SSVTest;

model XLSTest "Excel XLS file read test"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><!-- test.ssv -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- test_v1.ssv -->
<ssv:ParameterSet version="1.0" name="set1"
xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues">
<ssv:Parameters>
Expand Down
23 changes: 23 additions & 0 deletions ExternData/Resources/Examples/test_v2.ssv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- test_v2.ssv -->
<ssv:ParameterSet version="2.0" name="set1"
xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon"
xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues">
<ssv:Parameters>
<ssv:Parameter name="gain.k">
<ssv:Float64 value="2"/>
</ssv:Parameter>
<ssv:Parameter name="clock.offset">
<ssv:Float64 value="0.1"/>
</ssv:Parameter>
<ssv:Parameter name="vector">
<ssv:Float64 value="1 2 3"/>
<ssc:Dimension size="3"/>
</ssv:Parameter>
<ssv:Parameter name="table1">
<ssv:Float64 value="0 0 0.5 0.25 1 1"/>
<ssc:Dimension size="3"/>
<ssc:Dimension size="2"/>
</ssv:Parameter>
</ssv:Parameters>
</ssv:ParameterSet>
Loading

0 comments on commit 2f3c7b8

Please sign in to comment.