...
...
...
...
Table of Contents | ||
---|---|---|
|
Library
RT-LAB/DataLogging
Block
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
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 ...
The OpWriteFile block starts recording as soon as the simulation starts. However, the block can be used with RT-LAB's OpTrigger block to set the condition for writing to the file. The acquisition group must be the same in both blocks.
Once the file is triggered and the recording completed (i.e. the File size limit was reached), then the .mat file is not overwritten if the OpTrigger block is triggered again.
Unchecking the static filename option can be used to record several files during the same simulation (see below for more details).
Once the logging is completed or the model is reset, the file is transferred back to the localhost computer (i.e. the Windows computer running RT-LAB).
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:
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.
|
| |
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
If the parameters Buffer size and File size limit are not properly set, the resulting file may be empty.
Buffer Size Equation
The equation is:
Buffer size (bytes) >= (Number of logged signals + 1) x (Number of Samples per Signal) x 8
where,
The Time signal is automatically added as in the first row; thus, the +1 for the number of logged signals.
A double (Simulink signal type is double by default) is composed of 64 bits or 8 bytes; thus, the x8 at the end to have the size in bytes
Number of Samples per Signals is arbitrary, but 1000 is a good starting point.
File Size Limit Equation
The equation is:
File size (bytes) = 1.5*(Number of logged signals + 1) x 8 x (Logging duration(s)) / (Decimation factor x Sample time(s))
Where,
The factor of 1.5 at the beginning is because there is an extra header space that must be taken into account when calculating the File size for the OpWriteFile block. This header varies according to the number of signals and other factors. Therefore, 1.5 is a rule of thumb to make sure the file size is sufficient, but it can be modified depending on the use case.
A double (Simulink signal type is double by default) is composed of 64 bits or 8 bytes; thus, the x8 to have the size in bytes.
Sample Time is the time step of the simulation (typ. 25 or 50 us)
Logging duration is arbitrary.
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 |