Target Language Compiler | ![]() ![]() |
Built-In Functions and Values
Table 6-5, TLC Built-in Functions and Values, lists the built-in functions and values that are added to the list of parameters that appear in the model.rtw
file. These Target Language Compiler functions and values are defined in uppercase so that they are visually distinct from other parameters in the model.rtw
file, and by convention, from user-defined parameters.
Built-In Function Name |
Expansion |
|
The first expression must be a string that corresponds to one of the type names in the Target Language Values table, and the second expression will be cast to that type. A typical use might be to cast a variable to a real format as in CAST("Real", variable-name ) An example of this is in working with parameter values for S-functions. To use them within C code, you need to typecast them to real so that a value such as "1" will be formatted as "1.0" (see also %realformat ). |
|
If the var identifier is not currently in scope, the result is TLC_FALSE. If the identifier is in scope, the result is TLC_TRUE . var can be a single identifier or an expression involving the . and [] operators.Note: prior to TLC release 4, the semantics of EXISTS differed from the above. See Compatibility Issues. |
FEVAL(matlab-command, |
Performs an evaluation in MATLAB. For example%assign result = FEVAL("sin",3.14159) The %matlab directive can be used to call a MATLAB function that does not return a result. For example, %matlab disp(2.718) Note: if the MATLAB function returns more than one value, TLC only receives the first value. |
|
expr must be a string. If a file by the name expr does not exist on the path, the result is TLC_FALSE . If a file by that name exists on the path, the result is TLC_TRUE . |
FORMAT( |
The first expression is a Real value to format. The second expression is either "EXPONENTIAL " or "CONCISE ". Outputs the Real value in the designated format where EXPONENTIAL uses exponential notation with 16 digits of precision, and CONCISE outputs the number in a more readable format while maintaining numerical accuracy. |
FIELDNAMES( |
Returns a array of strings containing the record field names associated with the record. As it returns a sorted list of strings, function is O(n*log(n)). |
GETFIELD( |
Returns the contents of the specified field name, if the field name is associated with the record. By virtue of hash lookup, executes in constant time |
|
This is used to execute function calls mapped to a specific record type (i.e., Block record functions). For example, use this to execute the functions in the .tlc files for built-in blocks. Note, TLC automatically "scopes" or adds the first argument to the list of scopes searched as if it appears on a %with directive line. |
|
For the specified record type, does a .tlc file exist? Use this to see if the GENERATE_TYPE call will succeed. |
GENERATE_FORMATTED_VALUE |
Returns a potentially multiline string that can be used to declare the value(s) of expr in the current target language. The second argument is a string that is used as the variable name in a descriptive comment on the first line of the return string. If the second argument is the empty string, "" , then no descriptive comment is put into the output string. |
GENERATE_FUNCTION_EXISTS |
Determines if a given block function exists. The first expression is the same as the first argument to GENERATE , namely a block scoped variable containing a Type . The second expression is a string that should match the function name. |
GENERATE_TYPE |
Similar to GENERATE , except type overrides the Type field of the record. Use this when executing functions mapped to specific S-function blocks records based upon the S-function name (i.e., name becomes type). |
GENERATE_TYPE_FUNCTION_EXISTS |
Same as GENERATE_FUNCTION_EXISTS except it overrides the Type built into the record. |
|
Returns the value of command-line switches. Only the following switches are supported: v, m, p, O, d, r, I, a See also Command Line Arguments |
|
expr must be a string. The result is a vector where the first element is a leading string (if any) and the second element is a number appearing at the end of the input string. For example:
|
IMAG(expr) |
Returns the imaginary part of a complex number. |
INT8MAX |
127 |
INT8MIN |
-128 |
INT16MAX |
32767 |
INT16MIN |
-32768 |
INT32MAX |
2147483647 |
INT32MIN |
-2147483648 |
INTMIN |
Minimum integer value on target machine |
INTMAX |
Maximum integer value on target machine |
|
Returns TLC_TRUE if the record is a reference (symbolic link) to a different record, and TLC_FALSE otherwise. |
ISEQUAL |
Where the datatypes of both expressions are numeric: returns TLC_TRUE if the first expression contains the same value as the second expression; returns TLC_FALSE otherwise.Where the datatype of either expression is non- numeric (e.g. string or record): returns TLC_TRUE if and only if both expressions have the same datatype and contain the same value; returns TLC_FALSE otherwise. |
ISEMPTY(expr) |
Returns TLC_TRUE if the expression contains an empty string, vector, or record, and TLC_FALSE otherwise. |
ISFIELD(record, "fieldname") |
Returns TLC_TRUE if the field name is associated to the record, and TLC_FALSE otherwise. |
ISINF(expr) |
Returns TLC_TRUE if the value of the expression is inf and TLC_FALSE otherwise. |
ISNAN(expr) |
Returns TLC_TRUE if the value of the expression is NAN , and TLC_FALSE otherwise. |
ISFINITE(expr) |
Returns TLC_TRUE if the value of the expression is not +/- inf or NAN, and TLC_FALSE otherwise. |
NULL_FILE |
A predefined file for no output that you can use as an argument to %selectfile to prevent output. |
|
The number of target files used thus far in expansion. |
OUTPUT_LINES |
Returns the number of lines that have been written to the currently selected file or buffer. Does not work for STDOUT or NULL_FILE |
REAL(expr) |
Returns the real part of a complex number. |
|
Removes the specified field from the contents of the record. Returns TLC_TRUE if the field was removed; otherwise returns TLC_FALSE . |
ROLL_ITERATIONS() |
Returns the number of times the current roll regions are looping or NULL if not inside a %roll construct. |
|
Sets the contents of the field name associated to the record. Returns TLC_TRUE if the field was added; otherwise returns TLC_FALSE . |
|
Calculates the size of the first expression and generates a two-element, row vector. If the second operand is specified, it is used as an integral index into this row vector; otherwise the entire row vector is returned. SIZE(x) applied to any scalar returns [1 1] . SIZE(x) applied to any scope returns the number of repeated entries of that scope type (e.g., SIZE(Block) returns [1,<number of blocks>] . |
|
Formats the data in variable var (and in any additional variable arguments) under control of the specified format string, and returns a string variable containing the values. Operates like C library sprintf() , except that output is the return value rather than contained in an argument to sprintf . |
STDOUT |
A predefined file for stdout output. You can use this as an argument to %selectfile to force output to stdout . |
|
Expands the expression into a string; the characters \ , \n , and " are escaped by preceding them with \ (backslash). All the ANSI escape sequences are translated into string form. |
STRINGOF(expr) |
Accepts a vector of ASCII values and returns a string that is constructed by treating each element as the ASCII code for a single character. Used primarily for S-function string parameters in Real-Time Workshop. |
SYSNAME(expr) |
Looks for specially formatted strings of the form <x>/y and returns x and y as a 2-element string vector. This is used to resolve subsystem names in Real-Time Workshop. For example,
returns
In Block records, the name of the block is written similar to < sys / blockname > where sys is S# or Root . You can obtain the full pathname by calling LibGetBlockPath(block) ; this will include newlines and other troublesome characters that cause display difficulties. To obtain a full pathname suitable for one line comments but not identical to the Simulink pathname, use LibGetFormattedBlockPath(block) . |
TLCFILES |
Returns a vector containing the names of all the target files included thus far in the expansion. See also NUMTLCFILES . |
|
Boolean constant which equals a negative evaluated Boolean expression. |
|
Boolean constant which equals a positive evaluated Boolean expression. |
|
The date and time of compilation. |
|
The version and date of the Target Language Compiler. |
|
Evaluates expr and determines the result type. The result of this function is a string that corresponds to the type of the given expression. See value type string in Table 6-2, Target Language Values for possible values. |
UINT8MAX |
255U |
UINT16MAX |
65535U |
UINT32MAX |
4294967295U |
UINTMAX |
Maximum unsigned integer value on target machine. |
WHITE_SPACE(expr) |
Accepts a string and returns 1 if the string contains only whitespace characters ( , \t , \n , \r ); returns 0 otherwise. |
WILL_ROLL(expr1, expr2) |
The first expression is a roll vector and the second expression is a roll threshold. This function returns true if the vector contains a range that will roll. |
The FEVAL
built-in function calls MATLAB M-file functions and MEX-functions. The structure is
This table shows the conversions that are made when calling MATLAB.
When values are returned from MATLAB, they are converted as shown in this table. Note that conversion of matrices with more than 2 dimensions is not supported, nor is conversion or downcast of 64-bit integer values,
Other value types are not currently supported.
As an example, this statement uses the FEVAL
built-in function to call MATLAB to take the sine of the input argument.
Variables (identifiers) can take on the following constant values. Note the suffix on the value one.
Constant Form |
TLC Type |
1.0 |
"Real" |
1.0[F/f] |
"Real32" |
1 |
"Number" |
1[U|u] |
"Unsigned" |
1.0i |
"Complex" |
1[Ui|ui] |
"UnsignedGaussian" |
1i |
"Gaussian" |
1.0[Fi|fi] |
"Complex32" |
This table shows Target Language Compiler constants and their equivalent MATLAB values.
TLC Constant(s) |
Equivalent MATLAB Value |
rtInf , Inf , inf |
+inf |
rtMinusInf |
-inf |
rtNan , NaN , nan |
nan |
rtInfi, Infi , infi |
inf*i |
rtMinusInfi |
-inf*i |
rtNaNi , NaNi , nani |
nan*i |
![]() | Asserts, Errors, Warnings, and Debug Messages | TLC Reserved Constants | ![]() |