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_basicsc.c file header that is generated using this default template:

/*
* File: rtwdemo_basicsc.c
*
* Code generated for Simulink model 'rtwdemo_basicsc'.
*
* Model version                  : 1.299
* Simulink Coder version         : 8.11 (R2017a) 01-Aug-2016
* C/C++ source code generated on : Fri Aug 19 12:45:59 2016
*
* 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. Display the active Templates configuration parameters.

  2. In the Code templates section of the Templates pane, type code_c_template.cgt into the Source file (*.c) templates text box.

  3. Type code_h_template.cgt into the Header file (*.h) templates text box.

  4. In the Data templates section, type data_c_template.cgt into the Source file (*.c) templates text box.

  5. Type data_h_template.cgt into the Header file (*.h) templates text box, and click Apply.

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

    /**
     *******************************************************************************
     **  FILE INFORMATION:
     **  Filename:           rtwdemo_basicsc.c
     **  File Creation Date: 19-Aug-2016
     **
     **  ABSTRACT:
     **
     **
     **  NOTES:
     **
     **
     **  MODEL INFORMATION:
     **  Model Name:         rtwdemo_basicsc
     **  Model Description:  Specifying Storage Class Within a Diagram
    
       This model shows how to define data storage class as part of
       the diagram.
     **  Model Version:      1.299
     **  Model Author:       The MathWorks, Inc. - Mon Nov 27 14:36:56 2000
     **
     **  MODIFICATION HISTORY:
     **  Model at Code Generation: user - Fri Aug 19 12:47:36 2016
     **
     **  Last Saved Modification:  The MathWorks, Inc. - Sat Aug 06 14:37:49 2016
     **
     **
     *******************************************************************************
     **/