Documentation Center

  • Trial Software
  • Product Updates

Generate Reusable Code for Unit Testing

How to Generate Reusable Code for Linked Atomic Subcharts

To specify code generation parameters for linked atomic subcharts from the same library:

  1. Open the library model that contains your atomic subchart.

  2. Unlock the library.

  3. Right-click the library chart and select Block Parameters.

  4. In the dialog box, specify the following parameters:

    1. On the Main tab, select Treat as atomic unit.

    2. On the Code Generation tab, set Function packaging to Reusable function.

    3. Set File name options to User specified.

    4. For File name, enter the name of the file with no extension.

    5. Click OK to apply the changes.

  5. (OPTIONAL) Customize the generated function names for atomic subcharts:

    1. Open the Model Configuration Parameters dialog box.

    2. On the Code Generation pane, set System target file to ert.tlc.

    3. Navigate to the Code Generation > Symbols pane.

    4. For Subsystem methods, specify the format of the function names using a combination of the following tokens:

      • $R — root model name

      • $F — type of interface function for the atomic subchart

      • $N — block name

      • $H — subsystem index

      • $M — mangle string

    5. Click OK to apply the changes.

When you generate code for your model, a separate file stores the code for linked atomic subcharts from the same library.

How to Generate Reusable Code for Unlinked Atomic Subcharts

To specify code generation parameters for an unlinked atomic subchart:

  1. In your chart, right-click the atomic subchart and select Properties.

  2. In the dialog box, specify the following parameters:

    1. Set Code generation function packaging to Reusable function.

    2. Set Code generation file name options to User specified.

    3. For Code generation file name, enter the name of the file with no extension.

    4. Click OK to apply the changes.

  3. (OPTIONAL) Customize the generated function names for atomic subcharts:

    1. Open the Model Configuration Parameters dialog box.

    2. On the Code Generation pane, set System target file to ert.tlc.

    3. Navigate to the Code Generation > Symbols pane.

    4. For Subsystem methods, specify the format of the function names using a combination of the following tokens:

      • $R — root model name

      • $F — type of interface function for the atomic subchart

      • $N — block name

      • $H — subsystem index

      • $M — mangle string

    5. Click OK to apply the changes.

When you generate code for your model, a separate file stores the code for the atomic subchart. For more information, see Generate Reusable Code for Unit Testing.

Was this topic helpful?