Skip to content

Commit

Permalink
No records
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Jan 16, 2025
1 parent d4448a6 commit 871d7db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 78 deletions.
68 changes: 12 additions & 56 deletions ExternData/Examples/package.mo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package Examples "Test examples"

model CSVTest "CSV file read test"
extends Modelica.Icons.Example;
inner parameter ExternData.CSVFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.csv")) "CSV file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.CSVFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.csv")) "CSV file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
final parameter Integer m = dataSource.getArrayRows2D() "Number of rows in 2D array";
Modelica.Blocks.Sources.TimeTable timeTable(table=dataSource.getRealArray2D(3, 2)) annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
annotation(experiment(StopTime=1),
Expand All @@ -23,7 +23,7 @@ package Examples "Test examples"
model INITest "INI file read test"
extends Modelica.Icons.Example;
parameter String setName = "set1" "Parameter set name" annotation(Evaluate=true, choices(choice="set1" "First parameter set", choice="set2" "Second parameter set"));
inner parameter ExternData.INIFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.ini")) "INI file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.INIFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.ini")) "INI file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal("gain.k", setName)) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Math.Gain gain2(k=Modelica.Utilities.Strings.scanReal(dataSource.getString("gain.k", setName))) annotation(Placement(transformation(extent={{-15,30},{5,50}})));
Modelica.Blocks.Sources.ContinuousClock clock annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
Expand All @@ -37,7 +37,7 @@ package Examples "Test examples"
model JSONTest "JSON file read test"
extends Modelica.Icons.Example;
parameter String setName = "set1" "Parameter set name" annotation(Evaluate=true, choices(choice="set1" "First parameter set", choice="set2" "Second parameter set"));
inner parameter ExternData.JSONFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.json")) "JSON file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.JSONFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.json")) "JSON file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal(setName + ".gain.k")) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Math.Gain gain2(k=Modelica.Utilities.Strings.scanReal(dataSource.getString(setName + ".gain.k"))) annotation(Placement(transformation(extent={{-15,30},{5,50}})));
Modelica.Blocks.Sources.ContinuousClock clock annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
Expand All @@ -52,7 +52,7 @@ package Examples "Test examples"

model MATTest "MAT-file read test"
extends Modelica.Icons.Example;
inner parameter ExternData.MATFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test_v7.3.mat")) "MAT file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.MATFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test_v7.3.mat")) "MAT file" annotation(Placement(transformation(extent={{-80,60},{-60,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,60},{-30,80}})));
annotation(experiment(StopTime=1),
Expand All @@ -61,7 +61,7 @@ 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_v2.ssv")) "SSV file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner 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";
Expand All @@ -75,34 +75,12 @@ package Examples "Test examples"
model XLSTest "Excel XLS file read test"
extends Modelica.Icons.Example;
parameter String sheetName = "set1" "Excel sheet name" annotation(Evaluate=true, choices(choice="set1" "First Excel sheet", choice="set2" "Second Excel sheet"));
inner parameter ExternData.XLSFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xls")) "XLS file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.XLSFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xls")) "XLS file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal("B2", sheetName)) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Math.Gain gain2(k=Modelica.Utilities.Strings.scanReal(dataSource.getString("B2", sheetName))) annotation(Placement(transformation(extent={{-15,30},{5,50}})));
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("A1", "table1", 3, 2)) annotation(Placement(transformation(extent={{-50,30},{-30,50}})));
final parameter Real sumB = computeColSum(dataSource, "B") "Sum of column B";
function computeColSum "Compute column sum"
extends Modelica.Icons.Function;
input ExternData.XLSFile dataSource "Excel XLS file record";
input String col = "A" "Column";
input String sheetName = "" "Sheet name";
input Integer startRow = 2 "Start row";
input Integer endRow = ExternData.Functions.XLS.getArrayRows2D(sheetName=sheetName, xls=dataSource.xls) "End row";
output Real colSum "Column sum";
protected
Real val;
Boolean exist;
algorithm
colSum := 0.0;
for row in startRow:endRow loop
(val, exist) := ExternData.Functions.XLS.getReal(cellAddress=col + String(row), sheetName=sheetName, xls=dataSource.xls);
if exist then
colSum := colSum + val;
end if;
end for;
annotation(Documentation(info="<html><p>This function computes the column sum of a given column and sheet of an Excel XLS file.</p></html>"));
end computeColSum;
equation
connect(clock.y,gain1.u) annotation(Line(points={{-29,70},{-17,70}}, color={0,0,127}));
connect(clock.y,gain2.u) annotation(Line(points={{-29,70},{-22,70},{-22,40},{-17,40}}, color={0,0,127}));
Expand All @@ -113,34 +91,12 @@ package Examples "Test examples"
model XLSXTest "Excel XLSX file read test"
extends Modelica.Icons.Example;
parameter String sheetName = "set1" "Excel sheet name" annotation(Evaluate=true, choices(choice="set1" "First Excel sheet", choice="set2" "Second Excel sheet"));
inner parameter ExternData.XLSXFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xlsx")) "XLSX file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.XLSXFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xlsx")) "XLSX file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal("B2", sheetName)) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Math.Gain gain2(k=Modelica.Utilities.Strings.scanReal(dataSource.getString("B2", sheetName))) annotation(Placement(transformation(extent={{-15,30},{5,50}})));
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("A1", "table1", 3, 2)) annotation(Placement(transformation(extent={{-50,30},{-30,50}})));
final parameter Real sumB = computeColSum(dataSource, "B") "Sum of column B";
function computeColSum "Compute column sum"
extends Modelica.Icons.Function;
input ExternData.XLSXFile dataSource "Excel XLSX file record";
input String col = "A" "Column";
input String sheetName = "" "Sheet name";
input Integer startRow = 2 "Start row";
input Integer endRow = ExternData.Functions.XLSX.getArrayRows2D(sheetName=sheetName, xlsx=dataSource.xlsx) "End row";
output Real colSum "Column sum";
protected
Real val;
Boolean exist;
algorithm
colSum := 0.0;
for row in startRow:endRow loop
(val, exist) := ExternData.Functions.XLSX.getReal(cellAddress=col + String(row), sheetName=sheetName, xlsx=dataSource.xlsx);
if exist then
colSum := colSum + val;
end if;
end for;
annotation(Documentation(info="<html><p>This function computes the column sum of a given column and sheet of an Excel XLSX file.</p></html>"));
end computeColSum;
equation
connect(clock.y,gain1.u) annotation(Line(points={{-29,70},{-17,70}}, color={0,0,127}));
connect(clock.y,gain2.u) annotation(Line(points={{-29,70},{-22,70},{-22,40},{-17,40}}, color={0,0,127}));
Expand All @@ -151,7 +107,7 @@ package Examples "Test examples"
model XMLTest "XML file read test"
extends Modelica.Icons.Example;
parameter String setName = "set1" "Parameter set name" annotation(Evaluate=true, choices(choice="set1" "First parameter set", choice="set2" "Second parameter set"));
inner parameter ExternData.XMLFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xml")) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.XMLFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xml")) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal(setName + ".gain.k")) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Math.Gain gain2(k=Modelica.Utilities.Strings.scanReal(dataSource.getString(setName + ".gain.k"))) annotation(Placement(transformation(extent={{-15,30},{5,50}})));
Modelica.Blocks.Sources.ContinuousClock clock annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
Expand All @@ -167,7 +123,7 @@ package Examples "Test examples"
model XMLTestInnerOuter "XML file read test (utilizing inner/outer hierarchy)"
extends Modelica.Icons.Example;
inner parameter String setName = "set1" "Parameter set name" annotation(Evaluate=true, choices(choice="set1" "First parameter set", choice="set2" "Second parameter set"));
inner parameter ExternData.XMLFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xml")) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.XMLFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xml")) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
model Component
outer parameter String setName "Parameter set name";
extends ExternData.Interfaces.DataSourceModel;
Expand All @@ -192,7 +148,7 @@ package Examples "Test examples"
extends Modelica.Icons.Example;
parameter String setName = "set1" "Parameter set name" annotation(Evaluate=true, choices(choice="set1" "First parameter set", choice="set2" "Second parameter set"));
parameter String fileName = Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xml") "File where external data is stored";
inner parameter ExternData.XMLFile dataSource(fileName=fileName) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.XMLFile dataSource(fileName=fileName) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal(setName + ".gain.k")) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Math.Gain gain2(k=Modelica.Utilities.Strings.scanReal(dataSource.getString(setName + ".gain.k"))) annotation(Placement(transformation(extent={{-15,30},{5,50}})));
Modelica.Blocks.Sources.ContinuousClock clock annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
Expand All @@ -209,7 +165,7 @@ package Examples "Test examples"
model XMLTestXPath "XML file read test (utilizing XPath expressions)"
extends Modelica.Icons.Example;
parameter String setName = "set1" "Parameter set name" annotation(Evaluate=true, choices(choice="set1" "First parameter set", choice="set2" "Second parameter set"));
inner parameter ExternData.XML2File dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xml")) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.XML2File dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test.xml")) "XML file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Math.Gain gain1(k=dataSource.getReal("//" + setName + "/gain/k")) annotation(Placement(transformation(extent={{-15,60},{5,80}})));
Modelica.Blocks.Math.Gain gain2(k=Modelica.Utilities.Strings.scanReal(dataSource.getString("//" + setName + "/gain/k"))) annotation(Placement(transformation(extent={{-15,30},{5,50}})));
Modelica.Blocks.Sources.ContinuousClock clock annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
Expand All @@ -224,7 +180,7 @@ package Examples "Test examples"

model TIRTest "TIR file read test"
extends Modelica.Icons.Example;
inner parameter ExternData.TIRFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/sample.tir")) "TIR file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
inner ExternData.TIRFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/sample.tir")) "TIR file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
Modelica.Blocks.Sources.Constant pcx1(k=dataSource.getReal("PCX1", "LONGITUDINAL_COEFFICIENTS")) annotation(Placement(transformation(extent={{-50,60},{-30,80}})));
Modelica.Blocks.Sources.Constant pcy1(k=dataSource.getReal("PCY1", "LATERAL_COEFFICIENTS")) annotation(Placement(transformation(extent={{-50,30},{-30,50}})));
annotation(experiment(StopTime=1),
Expand Down
Loading

0 comments on commit 871d7db

Please sign in to comment.