Target Language Compiler    

Passing and Using a Parameter

As we described above, and as you demonstrated by using the built-in function GET_COMMAND_SWITCH(), you can use the MATLAB tlc command to pass parameters from the command line to the TLC file being executed. The most general command switch is -a, which assigns arbitrary variables. For example:

The result of passing this pair of strings via -a is the same as declaring and initializing local variables in the file being executed (here, any.tlc), i.e.,

Note that such variables need not be declared in the TLC file, and are available for use when set with -a. However, errors result if the code assigns undeclared variables that are not specified by an -a switch when invoking the file. Also note that (in contrast to the -r switch) no space should separate -a from the parameter being declared.

In the final section of this exercise, we provide a parameter to control whether or not the names of blocks are printed out. By default block names are listed, but are suppressed if the command line contains -alist=0.

  1. Open listrtw2.tlc in your editor and save it as listrtw3.tlc
  1. Below the line %include "utillib.tlc" you need to check whether a list parameter has been declared, via the intrinsic (built-in) function EXISTS(). Should no list variable exist, your program assigns one:

    This code ensures that list is defined and by default its value is TRUE.

  1. Next, enclose the line that prints block names within an %if block:
  1. Now LibGetFormattedBlockPath is called and expanded into text only when list is TRUE.

  1. Save listrtw3.tlc and cverify that your changes work as expected, using the command
  1. With the -alist=0 switch, the output resembles that from listrtw1.tlc, except that the input filename is reported as well as the block and subsystem counts.

  1. Finally, execute listrtw3.tlc with the command:
  1. tlc -r f14a.rtw listrtw3.tlc

    This yields the same results as you obtained with listrtw2.tlc. Here is the output printed to the MATLAB command window:

Congratulations! You have crafted several Target Language Compiler programs that access model.rtw files, and run them from the command line.


  Listing Block Names Inlining S-Functions with TLC