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.

...

...

Mask

...

Description

The OpWriteFile block writes time and input signal(s) to a specified MAT file on the target, one column for each timestep. The first row is the simulation time (automatically added); the second row is the first element of the input vector signal and so on ...

...

For instance, if the target is Linux-based and a relative path is used, then the file is transferred back to the OpREDHAWKtarget folder of the corresponding subsystem. If the model is named rtdemo1 and the OpWriteFile block is in the 'sm_computation' subsystem, then the file is transferred back to this path:  <Project directory>\models\rtdemo1\rtdemo1_sm_computation\OpREDHAWKtarget\ <name of file>.mat

Parameters

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 Path

Path where the file is located when the simulation is running on the target node. Default is './'.

Non-Real Time Path

Path 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 limit

When 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

This option will ignore the following features:

  • Trigger block (if any)

for
  • corresponding to the

corresponding "Buffer size in bytes" field
  • acquisition group

  • "Number of samples" field

    • Option “Number of samples“

    • Option “Buffer size in bytes“

    Number of samples

    Number 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 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.

    Inputs

    Data

    Signal input vector.

    File id

    The number that will be appended to the filename. Used only if Static filename parameter is unchecked.

    Outputs

    File Limit Reached

    Set to 1 when the file limit is reached.

    File status

    Set to 1 when file is opened, set to 0 when file is closed, and set to -1 when file is in closing state or in opening state. In offline mode (Simulink mode), this output is always 1.

    Equations to Calculate the Different Parameters of the OpWriteFile Block

    ...

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

    ...

    Example CSV File for Dynamic Filename Mode (Column 1)

    , out_folder/out_file_a.mat
    , out_folder/out_file_b.mat
    , alternative_out_folder/out_file_c.mat

    Characteristics and Limitations

    Direct Feedthrough

    Yes

    Discrete sample time

    No

    XHP support

    Yes (Partial XHP only)

    Work offline

    Yes