MX_SLFS – Save or load a Matrix/Vector into file or string

Block SymbolLicensing group: STANDARD
PIC

Function Description
The block allows to convert a matrix or vector into text form and vice versa. The matrix is supplied as a reference to the uMV input. The yMV output refers to the same matrix as the uMV input, and is intended to chain matrix blocks in the correct order, as is common with all MATRIX blocks.   The text can be either in the input uStr (or output yStr for the opposite direction of conversion) or in the file. If the text is in a file, its name is the string connected to the uStr input. The usual REXYGENsystem file name rules applies , ie it is relative to datadir and ../ is not allowed to leave the directory. If the uStr input is unattached (or empty string), the path name of the file is used with the full path (that is, including the task name and all subsystems) with the .dat extension.

The format of a matrix in a text file or in text input and output is determined by the format parameter. Supported English and Czech CSV (i.e., columns separated by comma or semicolon), JSON format (created by Google and often used in web applications) and the format used by MATLAB (for entering a matrix in MATLAB scripts).

Conversion from text to matrix/vector or vice versa can be performed at each step of the algorithm or is triggered by the LOAD and SAVE inputs. The exact method is determined by the mode parameter and is explained in detail in the description of this parameter. If an error occurs, it is signaled to the iE output and in the log. After a fatal error, the conversion from/to the matrix stops. Error reset for mode = 1 .. 4 is done by setting LOAD = SAVE = off, resetting fatal error cannot be performed for mode = 5 .. 8 (must switch to mode = 1 .. 4 and then back).

The nmax parameter is used to alocate the output string. If nmax> 0, it is allocated specified number of chars during initialization. If this amount is insufficient, the block reports an error. If nmax = 0, the block increases the length of the output string as needed. If user don’t specify the nmax parameter it can lead to full RAM memory in extreme situations and unpredictable behaviour of entire system.

Inputs

uMV

Input reference to a matrix or vector

Reference

uStr

Input string (to convert into matrix) or filename

String

LOAD

Trigger to move data to matrix/vector

Bool

SAVE

Trigger to move data from matrix/vector

Bool

Parameters

mode

Triggering mode  2

Long (I32)

1 ....

level-triggered file

2 ....

edge-triggered file

3 ....

level-triggered string

4 ....

edge-triggered string

5 ....

continuous string to matrix

6 ....

continuous matrix to string

7 ....

continuous file to matrix

8 ....

continuous matrix to file

format

String/file format  1

Long (I32)

1 ....

CSV

2 ....

CSV(semicolon)

3 ....

JSON

4 ....

MATLAB

prec

Number of digits for single value   0  20 6

Long (I32)

TRN

Transposition flag

Bool

nmax

Allocated size of string   0

Long (I32)

Outputs

yMV

Output reference to a matrix or vector

Reference

yStr

String representation of the matrix/vector

String

iE

Error code

Error

2023 © REX Controls s.r.o., www.rexygen.com