Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel3

...

The OpWriteFile block is used to write signals to a binary file (.mat), files that are in the binary data container format that MATLAB uses.

OpWriteFile block

Mask

Description

...

Static filename

In static mode (i.e. the Static filename option is checked - default option), the file created will have the name specified in the Filename parameter. Once it is full, it cannot be overwritten for the rest of the simulation.

In dynamic mode (i.e. the Static filename option is unchecked),  a new input pin, called File ID, creates a new input pin on the block. The value of the File ID input will be appended to the name of the file.

Whenever the file id input signal changes, the block closes the current file (no matter if the recording is complete or not) before opening a new one with the new input value as a suffix for the name.

For example, assuming:

  • the Filename parameter is 'myfile.mat'
  • the static filename option is unchecked
  • a constant with a value of '12' is connected to the second input pin
  • There is no OpTrigger block

Then, as soon as the simulation starts, the OpWriteFile block will write to a file named 'myfle_12.mat'. Assuming the constant value changes from 12 to 15, then the file 'myfile_12.mat' will be closed (even though the max file is not reached) and a new one called 'myfile_15.mat' will be opened and the recording will continue in the new file.

If the OpTrigger block is present and the Static filename changes, the previous file will be closed but the OpTrigger block needs to be triggered again to start the recording in the new file.

Alternatively, the files names can be defined in a Comma-Separated Value (CSV) file. For this mode, the Filename parameter must follow the convention: "<name of file>.csv, <column to use starting from 0>". The input pin is then used to select the row number, starting from 0.

For example, if the Filename parameter is "csvfile.csv, 1" (the quotes are mandatory), the constant connected to the second input pin is set to 1, and the CSV file content is:

, out_folder/out_file_a.mat

, out_folder/out_file_b.mat

, alternative_out_folder/out_file_c.mat

Then, the filename used would be "out_file_b.mat".

Decimation factor

Specifies the decimation (or sampling) factor.

When set to 5, for example, the OpWriteFile block will save one sample every 5 steps, of each signal. The default value is 1.

Variable name

Name of the matrix contained in the named file.

This will be the name seen in the workspace when the file is opened in MATLAB.

Filename

Directory and name of the file that holds the data. If the file path does not exist, it will be created.

Path may be relative or absolute. See Static filename description for help on using dynamic file names.

Real-Time PathPath where the file is located when the simulation is running on the target node. Default is './'.
Non-Real Time PathPath where the file is located when the model is running on the localhost (Running under Windows OS). Default is '.\'.
Acquisition group

Specifies the acquisition group for all signals that go through this block. Options are 26 to 30.

File size limitWhen this limit is reached, the file is closed. See "Equation to Calculate the Different Parameters of OpWriteFile" to calculate the proper value.
Write in Simulink mode

When it is checked, the block writes a file when the simulation runs in Simulink. The .mat file is saved beside the model (.mdl or .slx).

Default is unchecked.

Simulation mode

Should be unchecked (default value) to use RT-LAB data acquisition architecture to save all signals without interfering with the real-time simulation.

When checked, the block goes in simulation without data loss mode. In this mode, all simulation signals' samples will be written to the file (i.e. the model running waits for the block to finish writing data to file before executing the next simulation step). Real-time is not respected in this mode.

Note
titleDisabled features

This option will ignore the following features:

  • Trigger block (if any) for the corresponding
to this OpWriteFile's acquisition group is disabled when this option is checked. When Simulation mode is checked, the
  • acquisition group
  • "Number of samples
and
  • " field
  • "Buffer size
parameters are ignored.
  • in bytes" field


Number of samplesNumber of samples (per signal) to be written at a time. When set to 1000 for example, the block will guarantee that there will be no data loss for every group of 1000 samples. Data loss (gaps) can only happen between packets of 1000 samples. If you are using an OpTrigger block for the same acquisition group, it is recommended to keep the default value (1000) for optimal writing efficiency.
Buffer size in bytes

Internally, the block uses a circular buffer to gather the Number of samples before writing any piece of data to the specified file. This parameter is the size in byte of this buffer. When setting this parameter, the user should consider the amount of memory available on the target node and the fact that each signal sample takes 8 bytes. Only complete buffers are written in the file; if the buffer size is high and cannot be filled up, the file will be empty.

Buffer size in bytes

Internally, the block uses a circular buffer to gather the Number of samples before writing any piece of data to the specified file. This parameter is the size (in bytes) of this buffer. When setting this parameter, the user should consider the amount of memory available on the target node and the fact that each signal sample takes 8 bytes. Only complete buffers are written in the file; if the buffer size is high and cannot be filled up, the file will be empty.

See "Equation to Calculate the Different Parameters of OpWriteFile" to calculate the proper value.

...

File size (bytes) = 1.5*(Number of logged signals +  11) x 8 x (Logging duration(s)) / (Decimation factor x Sample time(s))

...