Main Content

Template Symbols and Rules

Introduction

Template Symbol Groups and Template Symbols describe custom file processing (CFP) template symbols and rules for using them. The location of a symbol in one of the supplied template files (code_c_template.cgt, code_h_template.cgt, data_c_template.cgt, or data_h_template.cgt) determines where the items associated with that symbol are located in the corresponding generated file. Template Symbol Groups identifies the symbol groups, starting with the parent (“Base”) group, followed by the children of each parent. Template Symbols lists the symbols alphabetically.

Note

If you are using custom CGT sections, for files generated to the _sharedutils folder, you can only use symbol names in the Base symbol group.

Template Symbol Groups

Symbol GroupSymbol Names in This Group

Base (Parents)

Declarations

Defines

Definitions

Documentation

Enums

Functions

Includes

Types

Declarations

ExternalCalibrationLookup1D

ExternalCalibrationLookup2D

ExternalCalibrationScalar

ExternalVariableScalar

Defines

LocalDefines

LocalMacros

Definitions

FilescopeCalibrationLookup1D

FilescopeCalibrationLookup2D

FilescopeCalibrationScalar

FilescopeVariableScalar

GlobalCalibrationLookup1D

GlobalCalibrationLookup2D

GlobalCalibrationScalar

GlobalVariableScalar

Documentation

Abstract

Banner

Created

Creator

Date

Description

FileName

History

LastModifiedDate

LastModifiedBy

ModelName

ModelVersion

ModifiedBy

 

Notes

ToolVersion

Functions

CFunctionCode

Types

This parent has no children.

Template Symbols

Symbol Name*Symbol GroupSymbol ScopeSymbol Description (What the symbol puts in the generated file)

Abstract

Documentation

N/A

User-supplied description of the model or file. Placed in the generated file based on the Stateflow® note, Simulink® annotation, or DocBlock on the model.**

Banner

Documentation

N/A

Comments located near top of the file. Contains information that includes model and software versions, and date file was generated.

CFunctionCode

Functions

File

C/C++ functions. Must be at the bottom of the template.

Created

Documentation

N/A

Date when model was created. From Created on field on Model Properties dialog box.

Creator

Documentation

N/A

User who created model. From Created by field on Model Properties dialog box.

Date

Documentation

N/A

Date file was generated. Taken from computer clock.

Declarations

Base

 

Data declaration of a signal or parameter. For example, extern real_T globalvar;.

Defines

Base

File

Required #defines of .h files.

Definitions

Base

File

Data definitions of signals or parameters.

Description

Documentation

N/A

Description of model. From Model description field on Model Properties dialog box.**

Documentation

Base

N/A

Comments about how to interpret the generated files.

Enums

Base

File

Enumerated data type definitions.

ExternalCalibrationLookup1D

Declarations

External

***

ExternalCalibrationLookup2D

Declarations

External

***

ExternalCalibrationScalar

Declarations

External

***

ExternalVariableScalar

Declarations

External

***

FileName

Documentation

N/A

Name of the generated file.

FilescopeCalibrationLookup1D

Definitions

File

***

FilescopeCalibrationLookup2D

Definitions

File

***

FilescopeCalibrationScalar

Definitions

File

***

FilescopeVariableScalar

Definitions

File

***

Functions

Base

File

Generated function code.

GlobalCalibrationLookup1D

Definitions

Global

***

GlobalCalibrationLookup2D

Definitions

Global

***

GlobalCalibrationScalar

Definitions

Global

***

GlobalVariableScalar

Definitions

Global

***

History

Documentation

N/A

User-supplied revision history of the generated files. Placed in the generated file based on the Stateflow note, Simulink annotation, or DocBlock on the model.**

Includes

Base

File

#include preprocessor directives.

LastModifiedDate

Documentation

N/A

Date when model was last saved. From Last saved on field on Model Properties dialog box.

LastModifiedBy

Documentation

N/A

User who last saved model. From Last saved by field on Model Properties dialog box.

LocalDefines

Defines

File

#define preprocessor directives from code-generation data objects.

LocalMacros

Defines

File

C/C++ macros local to the file.

ModelName

Documentation

N/A

Name of the model.

ModelVersion

Documentation

N/A

Number incremented by 1 each time you save the model.

ModifiedBy

Documentation

N/A

Name of user who last modified the model.

Notes

Documentation

N/A

User-supplied miscellaneous notes about the model or generated files. Placed in the generated file based on the Stateflow note, Simulink annotation, or DocBlock on the model.**

ToolVersion

Documentation

N/A

A list of the versions of the toolboxes used in generating the code.

Types

Base

 

Data types of generated code.

* Symbol names must be enclosed between %< >. For example, %<Functions>.

** This symbol can be used to add a comment to the generated files. See Add Global Comments in the Generated Code. The code generator places the comment in each generated file whose template has this symbol name. The code generator places the comment at the location that corresponds to where the symbol name is located in the template file.

*** The description can be deduced from the symbol name. For example, GlobalCalibrationScalar is a symbol that identifies a scalar. It contains data of global scope that you can calibrate.

Rules for Modifying or Creating a Template

The following are the rules for creating an MPF template. Comparison of a Template and Its Generated File illustrates several of these rules.

  1. Place a symbol on a template within the %< > delimiter. For example, the symbol named Includes should look like this on a template: %<Includes>. Note that symbol names are case-sensitive.

  2. Place a symbol on a template where desired. Its location on the template determines where the item associated with this symbol is located in the generated file. If no item is associated with it, the symbol is ignored.

  3. Place a C/C++ statement outside of the %< > delimiter, and on a different line than a %< > delimiter, for that statement to appear in the generated file. For example, #pragma message ("my text") in the template results in #pragma message ("my text") at the corresponding location in the generated file. Note that the statement must be compatible with your C/C++ compiler.

  4. Use the .cgt extension for every template filename. ("cgt" stands for code generation template.)

  5. Note that %% $Revision: 1.1.4.10.4.1 $ appears at the top of the MathWorks supplied templates. This is for internal MathWorks use only. It does not need to be placed on a user-defined template and does not show in a generated file.

  6. Place a comment on the template between /* */ as in standard ANSI® C[1] . This results in /*comment*/ on the generated file.

  7. Each MPF template must have all of the Base group symbols, in predefined order. They are listed in Template Symbol Groups. Each symbol in the Base group is a parent. For example, Declarations is a parent symbol.

  8. Each symbol in a non-Base group is a child. For example, LocalMacros is a child.

  9. Except for Documentation children, children must be placed after their parent, before the next parent, and before the Functions symbol.

  10. Documentation children can be located before or after their parent in any order anywhere in the template.

  11. If a non-Documentation child is missing from the template, the code generator places the information associated with this child at its parent location in the generated file.

  12. If a Documentation child is missing from the template, the code generator omits the information associated with that child from the generated file.


[1] ANSI is a registered trademark of the American National Standards Institute, Inc.