Main Content

Change the Organization of a Generated File

The files created during code generation are organized according to the general code generation template. This template has the filename ert_code_template.cgt, and is specified by default in Code Generation > Templates pane of the Configuration Parameters dialog box.

The following fragment shows the rtwdemo_configinterface.c file header that is generated using this default template:

* File: rtwdemo_configinterface.c
* Code generated for Simulink model 'rtwdemo_configinterface'.
* Model version                  : 1.387
* Simulink Coder version         : 9.4 (R2020b) 19-May-2020
* C/C++ source code generated on : Thu Jun 11 14:31:07 2020
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run

You can change the organization of generated files using code templates and data templates. Code templates organize the files that contain functions, primarily. Data templates organize the files that contain identifiers. In this procedure, you organize the generated files, using the supplied code and data templates:

  1. In the Configuration Parameters dialog box, open the Code Generation > Templates pane.

  2. In the Code templates section, in the Source file template box, type code_c_template.cgt.

  3. In the Header file template box, type code_h_template.cgt.

  4. In the Data templates section, in the Source file template box, type data_c_template.cgt.

  5. In the Header file template box, type data_h_template.cgt.

  6. Click Apply.

  7. In the model window, press Ctrl+B. Now the files are organized using the templates you specified. For example, the rtwdemo_configinterface.c file header now is organized like this:

     **  Filename:           rtwdemo_configinterface.c
     **  File Creation Date: 11-Jun-2020
     **  ABSTRACT:
     **  NOTES:
     **  Model Name:         rtwdemo_configinterface
     **  Model Description:  Data Dictionary Driven Modeling Using 
         Simulink(R) Data Objects
       This model shows how to use Simulink data objects to define data 
       independently from the diagram which supports a data dictionary 
       driven modeling style.
     **  Model Version:      1.387
     **  Model Author:       The MathWorks, Inc. - Mon Nov 27 14:36:56 2000
     **  Model at Code Generation: user - Thu Jun 11 14:38:31 2020
     **  Last Saved Modification:  The MathWorks, Inc. - Thu Jun 04 02:05:40 2020