Buildings.Utilities.IO.Files

Reports package

Information

Package with models for writing data to files.

Extends from Modelica.Icons.Package (Icon for standard packages).

Package Content

Name Description
Buildings.Utilities.IO.Files.CSVWriter CSVWriter Model for writing results to a .csv file
Buildings.Utilities.IO.Files.CombiTimeTableWriter CombiTimeTableWriter Model for writing results to a format that is readable by the model CombiTimeTable
Buildings.Utilities.IO.Files.JSONWriter JSONWriter Model for writing results to a json file
Buildings.Utilities.IO.Files.Printer Printer Model that prints values to a file
Buildings.Utilities.IO.Files.Examples Examples Examples package
Buildings.Utilities.IO.Files.BaseClasses BaseClasses Package with base classes for Buildings.Utilities.IO.Files

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

Model for writing results to a .csv file

Buildings.Utilities.IO.Files.CSVWriter

Information

This model samples the model inputs u and saves them to a .csv file, which can be read using e.g. Excel or Python.

Typical use and important parameters

The parameter nin defines the number of variables that are stored. In Dymola, this parameter is updated automatically when inputs are connected to the component.

The parameter fileName defines to what file name the results are saved. The file is in the current working directory, unless an absolute path is provided.

The parameter samplePeriod defines every how many seconds the inputs are saved to the file.

Options

The parameter delimiter can be used to choose a custom separator.

By default the first line of the csv file consists of the file header. The column names can be defined using parameter headerNames. The header can be removed by setting writeHeader=false

Dynamics

This model samples the outputs at an equidistant interval and hence disregards the simulation tool output interval settings.

Extends from Buildings.Utilities.IO.Files.BaseClasses.FileWriter (Partial model for writing results to a .csv file).

Parameters

TypeNameDefaultDescription
StringfileNamegetInstanceName() + ".csv"File name, including extension
TimesamplePeriod Sample period: equidistant interval for which the inputs are saved [s]
Advanced
Stringdelimiter"\t"Delimiter for csv file
BooleanwriteHeadertrue=true, to write header with variable names, otherwise no header will be written
StringheaderNames[nin]{"col" + String(i) for i in ...Header names, indices by default
IntegersignificantDigits6Number of significant digits that are used for converting inputs into string format

Connectors

TypeNameDescription
input RealVectorInputu[nin]Variables that are saved

Modelica definition

model CSVWriter "Model for writing results to a .csv file" extends Buildings.Utilities.IO.Files.BaseClasses.FileWriter( final isCombiTimeTable=false); initial algorithm if writeHeader then str := str + "time" + delimiter; for i in 1:nin-1 loop str := str + headerNames[i] + delimiter; if mod(i+1,10)==0 then // write out buffer every 10 entries to avoid overflow writeLine(filWri, str, 1); str:=""; end if; end for; str := str + headerNames[nin] + "\n"; writeLine(filWri, str, 1); end if; end CSVWriter;

Buildings.Utilities.IO.Files.CombiTimeTableWriter Buildings.Utilities.IO.Files.CombiTimeTableWriter

Model for writing results to a format that is readable by the model CombiTimeTable

Buildings.Utilities.IO.Files.CombiTimeTableWriter

Information

This model samples the model inputs u and saves them to a .csv file, which can be read by a Modelica.Blocks.Sources.CombiTimeTable. The Modelica.Blocks.Sources.CombiTimeTable must then have tableName="csv", as illustrated in the example Buildings.Utilities.IO.Files.Examples.CSVReader.

Typical use and important parameters

The parameter nin defines the number of variables that are stored. In Dymola, this parameter is updated automatically when inputs are connected to the component.

The parameter fileName defines to what file name the results are saved. The file is in the current working directory, unless an absolute path is provided.

The parameter samplePeriod defines every how many seconds the inputs are saved to the file.

Options

By default the first line of the csv file consists of the file header. The column names can be defined using parameter headerNames or the header can be removed by setting writeHeader=false

Dynamics

This model samples the outputs at an equidistant interval and hence disregards the simulation tool output interval settings.

Extends from Buildings.Utilities.IO.Files.BaseClasses.FileWriter (Partial model for writing results to a .csv file).

Parameters

TypeNameDefaultDescription
StringfileNamegetInstanceName() + ".csv"File name, including extension
TimesamplePeriod Sample period: equidistant interval for which the inputs are saved [s]
Advanced
Stringdelimiter"\t"Delimiter for csv file
BooleanwriteHeadertrue=true, to write header with variable names, otherwise no header will be written
StringheaderNames[nin]{"col" + String(i) for i in ...Header names, indices by default
IntegersignificantDigits6Number of significant digits that are used for converting inputs into string format

Connectors

TypeNameDescription
input RealVectorInputu[nin]Variables that are saved

Modelica definition

model CombiTimeTableWriter "Model for writing results to a format that is readable by the model CombiTimeTable" extends Buildings.Utilities.IO.Files.BaseClasses.FileWriter( final delimiter="\t", final isCombiTimeTable=true); initial algorithm if writeHeader then str :="# time" + delimiter; for i in 1:nin-1 loop str :=str + headerNames[i] + delimiter; if mod(i+1,10)==0 then // write out buffer every 10 entries to avoid overflow writeLine(filWri, str, 1); str:=""; end if; end for; str :=str + headerNames[nin] + "\n"; writeLine(filWri, str, 1); end if; end CombiTimeTableWriter;

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

Model for writing results to a json file

Buildings.Utilities.IO.Files.JSONWriter

Information

This model samples the model inputs u and saves them to a json file.

Typical use and important parameters

The parameter nin defines the number of variables that are stored. In Dymola, this parameter is updated automatically when inputs are connected to the component.

The parameter fileName defines to what file name the results are saved. The file is in the current working directory, unless an absolute path is provided.

The parameter keyNames defines the key names that are used to store the json values corresponding to the inputs u.

Dynamics

This model samples its inputs at the time defined by the parameter outputTime and writes them to the file fileName. The model has the following options:

Extends from Modelica.Blocks.Icons.DiscreteBlock (Graphical layout of discrete block component icon).

Parameters

TypeNameDefaultDescription
StringfileNamegetInstanceName() + ".json"File name, including extension
StringvarKeys[nin]{"key" + String(i) for i in ...Key names, indices by default
OutputTimeoutputTimeBuildings.Utilities.IO.Files...Time when results are written to file
TimecustomTime0Custom time when results are stored, used if outputTime=Custom only [s]

Connectors

TypeNameDescription
input RealVectorInputu[nin]Variables that are saved

Modelica definition

model JSONWriter "Model for writing results to a json file" extends Modelica.Blocks.Icons.DiscreteBlock; parameter Integer nin "Number of inputs"; parameter String fileName = getInstanceName() + ".json" "File name, including extension"; parameter String[nin] varKeys = {"key" + String(i) for i in 1:nin} "Key names, indices by default"; parameter Buildings.Utilities.IO.Files.BaseClasses.OutputTime outputTime= Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Terminal "Time when results are written to file"; parameter Modelica.SIunits.Time customTime = 0 "Custom time when results are stored, used if outputTime=Custom only"; Modelica.Blocks.Interfaces.RealVectorInput[nin] u "Variables that are saved"; protected parameter String insNam = getInstanceName() "Instance name"; Buildings.Utilities.IO.Files.BaseClasses.JSONWriterObject jsonWri= Buildings.Utilities.IO.Files.BaseClasses.JSONWriterObject( insNam, fileName, outputTime==Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Terminal, varKeys) "File writer object"; equation if outputTime==Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Terminal then Buildings.Utilities.IO.Files.BaseClasses.cacheVals(jsonWri, u); end if; if outputTime==Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Initial then when initial() then Buildings.Utilities.IO.Files.BaseClasses.writeJSON(jsonWri, u); end when; end if; if outputTime==Buildings.Utilities.IO.Files.BaseClasses.OutputTime.Custom then when time>=customTime then Buildings.Utilities.IO.Files.BaseClasses.writeJSON(jsonWri, u); end when; end if; end JSONWriter;

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

Model that prints values to a file

Buildings.Utilities.IO.Files.Printer

Information

This model prints to a file or the terminal at a fixed sample interval.

The parameter configuration controls the printing as follows:

configurationconfiguration
1 print at sample times only
2 print at sample times and at end of simulation
3 print at end of simulation only

Extends from Modelica.Blocks.Interfaces.DiscreteBlock (Base class of discrete control blocks).

Parameters

TypeNameDefaultDescription
TimesamplePeriod Sample period of component [s]
TimestartTime0First sample time instant [s]
Stringheader""Header to be printed
StringfileName""File name (empty string is the terminal)
Integernin1Number of inputs
Integerconfiguration1Index for treating final report (see documentation)
IntegerminimumLength1Minimum length of result string
IntegersignificantDigits16Number of significant digits

Connectors

TypeNameDescription
input RealInputx[nin]Value to be printed

Modelica definition

model Printer "Model that prints values to a file" extends Modelica.Blocks.Interfaces.DiscreteBlock( firstTrigger( start=false, fixed=true)); parameter String header="" "Header to be printed"; parameter String fileName="" "File name (empty string is the terminal)"; parameter Integer nin=1 "Number of inputs"; parameter Integer configuration = 1 "Index for treating final report (see documentation)"; parameter Integer minimumLength = 1 "Minimum length of result string"; parameter Integer significantDigits = 16 "Number of significant digits"; Modelica.Blocks.Interfaces.RealInput x[nin] "Value to be printed"; initial algorithm if (fileName <> "") then Modelica.Utilities.Files.removeFile(fileName); end if; Modelica.Utilities.Streams.print(fileName=fileName, string=header); equation if configuration < 3 then when {sampleTrigger, initial()} then Buildings.Utilities.IO.Files.BaseClasses.printRealArray( x=x, fileName=fileName, minimumLength=minimumLength, significantDigits=significantDigits); end when; end if; when terminal() then if configuration >= 2 then Buildings.Utilities.IO.Files.BaseClasses.printRealArray( x=x, fileName=fileName, minimumLength=minimumLength, significantDigits=significantDigits); end if; end when; end Printer;