PartialSignalsFromFile partial block
Requirements.Sources.PartialSignalsFromFile
ยท source
Base of a reader of a MA-HS-CSV file: the extending block names the columns and declares one output per column
Syntax
block MyReader
extends Requirements.Sources.PartialSignalsFromFile(
final realNames = {"T_cabin", "p_cabin"},
final booleanNames = {"packOn"},
final integerNames = {"flightPhase"});
Modelica.Blocks.Interfaces.RealOutput T_cabin = Requirements.Internal.CSV.getReal(file, 1, time, nextTimeEvent, pre(nextTimeEvent));
Modelica.Blocks.Interfaces.RealOutput p_cabin = Requirements.Internal.CSV.getReal(file, 2, time, nextTimeEvent, pre(nextTimeEvent));
Modelica.Blocks.Interfaces.BooleanOutput packOn;
Modelica.Blocks.Interfaces.IntegerOutput flightPhase;
equation
when {fileEvent, initial()} then
packOn = Requirements.Internal.CSV.getBoolean(file, 1, time, nextTimeEvent, pre(nextTimeEvent));
flightPhase = Requirements.Internal.CSV.getInteger(file, 1, time, nextTimeEvent, pre(nextTimeEvent));
end when;
end MyReader;
MyReader reader(fileName="modelica://MyLibrary/Resources/Data/run1.csv");
Description
Reads a file in the Modelica Association's
MA-HS-CSV format (beta, 2026): RFC 4180 records,
a header row of unique column names, the first column the independent variable (time) with non-decreasing values,
consecutive rows with the same time representing an event (the rows carry the values before and after it),
fields containing a space, a comma, a double quote or a line break enclosed in double quotes ("" for a quote),
values in XML-Schema lexical form: Float64 as decimal or scientific notation, NaN, INF, -INF;
Boolean as true/false/1/0; integers as decimals. LF or CR LF line breaks, UTF-8 (a byte-order mark is skipped).
The file carries no type row: the extending block decides the type of every column it reads through the three name lists,
and declares one output per column, so the reader reads in a diagram like any block with named outputs:
Real outputs as declaration equations (they are continuous-time), Boolean and Integer outputs assigned in a when-clause with the
same trigger as the block's own, when {fileEvent, initial()}, because a discrete signal may only change
at an event and this is the event at which the file's Boolean and Integer columns change (the pattern of
BooleanTable).
fileEvent is clock >= pre(nextTimeEvent) with clock a state equal to time:
a state event, located by the integrator. The obvious time >= pre(nextTimeEvent) is a time event, and a time
event due a few ulps after another event of the model (a timer started at an event of the file, due at the instant a later
row of the file was written, from a time that differs in the last digits) is dropped by OCT as already past and never
retried: the reader would hold every Boolean and Integer column for the rest of the run (version 0.13.1).
Columns not named are skipped. A name that is not in the header, or a header name that appears twice, is an error when the file is opened
(at initialization), not a silent zero. Arrays (space-separated fields) are not supported; a numeric field containing a space is an error.
Signals from a field solver. A KPI that a CFD or FE solver writes over time (a force coefficient, a probe temperature) reaches a check the same way: the tool that extracts it writes the series as an MA-HS-CSV file, one column per KPI, and an extending block reads it like a measured signal. The KPI's uncertainty, when given as an interval [y − lower, y + upper], maps one to one onto the half-widths of PartialUncertaintyBand, in the value's unit. Chaperone does this for OpenFOAM and CalculiX results (its KPI trace replay); the library needs no block of its own for it.
Value semantics
- Real columns are linear between rows; at a group of rows with the same time the value jumps at that instant from the group's first row to its last row.
- Boolean and Integer columns are piecewise constant: the value of the last row whose time is ≤
time, stepping at the row's time. - Events: the block schedules a time event at every instant at which a Boolean or Integer column changes, or at which
any read column changes inside a same-time group, so
edge()andchange()downstream fire at the file's event instants. The value functions take the event bracket(nextTimeEvent, pre(nextTimeEvent)), as CombiTimeTable does, so the value on either side of an event is unambiguous during event iteration: before the when-clause has fired at the event instant the left value applies (a Real: the group's first row; a Boolean/Integer: the last row before the group), afterwards the right value. - Groups: rows whose times are within a relative 1e-10 of the first row of their group (equal, or a few ulps apart, as a simulator's result can hold) are one instant at that row's time. Two time events that close would be one the tool cannot schedule: the second would be dropped as already past, and the Boolean and Integer outputs would never change again.
- Outside the file's time range the first/last row is held (
extrapolateHold=true, the default), or an error is raised. - Row events (
rowEvents=true, since 0.20.1): the solver also stops at every row's time. A Real column is linear between rows, so its extremes lie on rows, and between two rows it crosses a fixed limit at most once (the difference of two columns too). Without row events nothing makes the solver stop inside a short excursion: a model with few or slow states can take one step across it, and a check reading the column, such asv <= 10, then never sees the limit crossed, although the value at an output point inside the excursion is above it. With row events no tool can miss it. The cost is one event per row, which matters for a long file (a year of hourly rows is 8760 events): set it where the checks must see every row, as a reader of a measured or a replayed trace.
A file chosen at run time (an exported FMU)
A tool resolves fileName when it translates the model: the file must exist then, and a tool that
exports an FMU copies it into the FMU's resources directory and reads it from there. Two ways to read
other data with the same translated model or FMU, without translating again:
runTimeFileName: an absolute path. It is not evaluated (Evaluate=false), so it stays a parameter of the translated model (in an FMUcausality="parameter",variability="fixed") and is set before initialization. When it is not empty it replacesfileName.- Replacing the packaged file in the FMU's
resourcesdirectory (the copy offileName) with a file of the same name.
The file is opened at initialization either way, so a file the run did not supply can be made to fail loudly: package a file with the header row only, which the reader rejects at initialization (no rows), and the FMU never runs on placeholder data.
fileName may be a modelica:// URI (resolved with
loadResource) or an absolute path. The C reader
(Resources/Include/RequirementsCsv.h, header-only) is compiled with the model; see
Internal.CSV. For an example see
Examples.Elementary.Sources.SignalsFromFile.
Copyright © 2026 Model Based Innovation LLC. All rights reserved.
Revisions
| Date | Description |
|---|---|
| Oct. 26, 2026 | runTimeFileName: a file chosen at run time, also in an exported FMU (version 0.14.0) |
| Sept. 14, 2026 | First version (H. Tummescheit, Model Based Innovation LLC) |
Parameters
| Name | Type | Description |
|---|---|---|
fileName parameter | String | MA-HS-CSV file: an absolute path, or a modelica:// URI |
extrapolateHold parameter | Boolean | = true: hold the first/last row outside the file's time range; = false: error |
rowEvents parameter | Boolean | = true: the solver stops at every row, so no excursion between two solver steps is missed (one event per row) |
runTimeFileName parameter | String | If not empty: the file read instead of fileName, an absolute path set at run time (e.g. a parameter of an exported FMU) |