Buildings.Utilities.IO.Files.Examples

Examples package

Information

This package contains examples for the use of models that can be found in Buildings.Utilities.IO.Files.

Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).

Package Content

Name Description
Buildings.Utilities.IO.Files.Examples.CSVReader CSVReader Reader for csv files generated by CSVWriter
Buildings.Utilities.IO.Files.Examples.CSVWriter CSVWriter Example of csv writer use
Buildings.Utilities.IO.Files.Examples.JSONWriter JSONWriter Example use of the JSON writer
Buildings.Utilities.IO.Files.Examples.Printer Printer Test model for printer
Buildings.Utilities.IO.Files.Examples.WeeklySchedule WeeklySchedule Weekly schedule example
Buildings.Utilities.IO.Files.Examples.WeeklySchedule7to19 WeeklySchedule7to19 Weekly schedule example that outputs 1 from 7:00 to 19:00 on week-days, and 0 otherwise
Buildings.Utilities.IO.Files.Examples.BaseClasses BaseClasses Package with base classes for Buildings.Utilities.IO.Files.Examples

Buildings.Utilities.IO.Files.Examples.CSVReader Buildings.Utilities.IO.Files.Examples.CSVReader

Reader for csv files generated by CSVWriter

Buildings.Utilities.IO.Files.Examples.CSVReader

Information

This model demonstrates how a CombiTimeTable can be used to read a text file that contains a table. The text file is stored in Buildings//Resources/Data/Utilities/IO/Files/Examples/CSVReader/Data.txt. It has the format of a file that can be generated by Buildings.Utilities.IO.Files.Examples.CSVWriter.

Extends from Buildings.Utilities.IO.Files.Examples.BaseClasses.PartialCSV (Base model for CSV reader and writer example).

Modelica definition

model CSVReader "Reader for csv files generated by CSVWriter" extends Buildings.Utilities.IO.Files.Examples.BaseClasses.PartialCSV; Modelica.Blocks.Sources.CombiTimeTable combiTimeTable( tableOnFile=true, fileName=Modelica.Utilities.Files.loadResource("modelica://Buildings//Resources/Data/Utilities/IO/Files/Examples/CSVReader/Data.txt"), columns={2,3}, tableName="tab") "Reader for test.csv"; end CSVReader;

Buildings.Utilities.IO.Files.Examples.CSVWriter Buildings.Utilities.IO.Files.Examples.CSVWriter

Example of csv writer use

Buildings.Utilities.IO.Files.Examples.CSVWriter

Information

This model demonstrates the use of the csv file writer.

Extends from Buildings.Utilities.IO.Files.Examples.BaseClasses.PartialCSV (Base model for CSV reader and writer example).

Modelica definition

model CSVWriter "Example of csv writer use" extends Buildings.Utilities.IO.Files.Examples.BaseClasses.PartialCSV; CombiTimeTableWriter combiTimeTableWriter( nin=2, samplePeriod=0.3, fileName="test.csv", significantDigits=10) "Model that writes two inputs to csv file in a format that can be read by a combiTimeTable"; Buildings.Utilities.IO.Files.CSVWriter csvWriter( writeHeader=false, nin=2, samplePeriod=0.3) "Duplicate to test for conflicts when instantiating multiple file writers"; equation connect(cos.y, combiTimeTableWriter.u[1]); connect(step.y, combiTimeTableWriter.u[2]); connect(csvWriter.u[1], cos.y); connect(csvWriter.u[2], step.y); end CSVWriter;

Buildings.Utilities.IO.Files.Examples.JSONWriter Buildings.Utilities.IO.Files.Examples.JSONWriter

Example use of the JSON writer

Buildings.Utilities.IO.Files.Examples.JSONWriter

Information

This model generates four json files, using a single or multiple inputs and at different points in time.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica definition

model JSONWriter "Example use of the JSON writer" extends Modelica.Icons.Example; Buildings.Utilities.IO.Files.JSONWriter jsonWriterInitial( nin=3, fileName="InitialOutputs.json", outputTime=Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Initial) "Outputs at initial time"; Buildings.Utilities.IO.Files.JSONWriter jsonWriterCustom( nin=3, outputTime=Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Custom, customTime=0.5, fileName="CustomOutputs.json", varKeys={"Output1","Key2","Name3"}) "Outputs at custom time"; Buildings.Utilities.IO.Files.JSONWriter jsonWriterTerminal( nin=3, outputTime=Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Terminal, fileName="TerminalOutputs.json") "Outputs at terminal time"; Modelica.Blocks.Sources.Ramp ramp( height=1, duration=1, offset=1) "Ramp signal"; Modelica.Blocks.Sources.Constant const(k=2) "Constant signal"; Modelica.Blocks.Sources.Cosine cosine(amplitude=1, f=12) "Cosine signal"; Buildings.Utilities.IO.Files.JSONWriter jsonWriterOneVar(nin=1, fileName="TerminalOutput.json") "Single variable output"; equation connect(ramp.y, jsonWriterInitial.u[1]); connect(const.y, jsonWriterInitial.u[2]); connect(cosine.y, jsonWriterInitial.u[3]); connect(ramp.y, jsonWriterCustom.u[1]); connect(ramp.y, jsonWriterTerminal.u[1]); connect(const.y, jsonWriterCustom.u[2]); connect(const.y, jsonWriterTerminal.u[2]); connect(cosine.y, jsonWriterCustom.u[3]); connect(cosine.y, jsonWriterTerminal.u[3]); connect(const.y, jsonWriterOneVar.u[1]); end JSONWriter;

Buildings.Utilities.IO.Files.Examples.Printer Buildings.Utilities.IO.Files.Examples.Printer

Test model for printer

Buildings.Utilities.IO.Files.Examples.Printer

Information

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica definition

model Printer "Test model for printer" extends Modelica.Icons.Example; Buildings.Utilities.IO.Files.Printer pri1( header="time ramp", nin=2, samplePeriod=0.1); Modelica.Blocks.Sources.ContinuousClock clo; Modelica.Blocks.Sources.Ramp ram(duration=2); Buildings.Utilities.IO.Files.Printer pri2( header="time ramp", nin=2, configuration=2, samplePeriod=0.1); Buildings.Utilities.IO.Files.Printer pri3( header="time ramp", nin=2, configuration=3, samplePeriod=0.1); equation connect(clo.y, pri1.x[1]); connect(ram.y, pri1.x[2]); connect(clo.y, pri2.x[1]); connect(ram.y, pri2.x[2]); connect(clo.y, pri3.x[1]); connect(ram.y, pri3.x[2]); end Printer;

Buildings.Utilities.IO.Files.Examples.WeeklySchedule Buildings.Utilities.IO.Files.Examples.WeeklySchedule

Weekly schedule example

Buildings.Utilities.IO.Files.Examples.WeeklySchedule

Information

Example and consistency test for a weekly schedule.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

TypeNameDefaultDescription
Stringdata"double tab1(3,5) #test: mon...Contents of schedule.txt

Modelica definition

model WeeklySchedule "Weekly schedule example" extends Modelica.Icons.Example; parameter String data = "double tab1(3,5) #test: mon:0:0:10 - 3 1 - tue,thu:20:30:59 123 - 45 - wed 12 1 4 -" "Contents of schedule.txt"; Buildings.Utilities.IO.Files.WeeklySchedule weeSchFil( columns={2,3,4,5}, tableOnFile=true, fileName=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/Data/schedule.txt"), t_offset=1e6) "Weekly schedule example using file data source"; Buildings.Utilities.IO.Files.WeeklySchedule weeSchStri( columns={2,3,4,5}, data=data, t_offset=1e6) "Weekly schedule example using parameter data source"; Diagnostics.AssertEquality assEqu[4]( each startTime=-10000, each threShold=Modelica.Constants.small) "Trigger an assertion if the outputs differ"; equation connect(weeSchFil.y, assEqu.u1); connect(weeSchStri.y, assEqu.u2); end WeeklySchedule;

Buildings.Utilities.IO.Files.Examples.WeeklySchedule7to19 Buildings.Utilities.IO.Files.Examples.WeeklySchedule7to19

Weekly schedule example that outputs 1 from 7:00 to 19:00 on week-days, and 0 otherwise

Buildings.Utilities.IO.Files.Examples.WeeklySchedule7to19

Information

Example of a weekly schedule that outputs 1 from 7:00 to 19:00 on week-days, and 0 otherwise

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica definition

model WeeklySchedule7to19 "Weekly schedule example that outputs 1 from 7:00 to 19:00 on week-days, and 0 otherwise" extends Modelica.Icons.Example; Buildings.Utilities.IO.Files.WeeklySchedule sch; end WeeklySchedule7to19;