%% Use |single| Data Type as Default for Underspecified Types
% This example shows how to avoid introducing a double-precision
% data type in code generated for a single-precision hardware target. 
%
% If you specify an inherited data type for signals, but
% data type propagation rules cannot determine data types for the signals,
% the signal data types default to |double|. You can use a model
% configuration parameter to specify the default data type as |single|.
%
% Copyright 2016 The MathWorks, Inc.
%% Explore Example Model
% Open the example model <matlab:rtwdemo_underspecified_datatype;set_param('rtwdemo_underspecified_datatype','HideAutomaticNames','off'); rtwdemo_underspecified_datatype> and configure it to show the generated names of blocks.
model = 'rtwdemo_underspecified_datatype';
load_system(model)
set_param(model,'HideAutomaticNames','off')
open_system(model);
%%
% The root inports |In2|, |In3|, and |In4| specify
% |Inherit: Auto| for the *Data type* block parameter. The downstream blocks also use
% inherited data types.
%% Generate Code with |double| as Default Data Type 
% The model starts with the configuration parameter *System target file*
% set to |ert.tlc|, which requires Embedded Coder. Set *System target file*
% to |grt.tlc| instead.
set_param(model,'SystemTargetFile','grt.tlc')
%%
% Generate code from the model.
rtwbuild(model)
%%
% In the code generation report, view the file
% |rtwdemo_underspecified_datatype.h|. The code uses the |double| data type
% to define the variables |In2|, |In3|, and |In4| because the Inport
% data types are underspecified in the model.
cfile = fullfile('rtwdemo_underspecified_datatype_grt_rtw',...
    'rtwdemo_underspecified_datatype.h');
rtwdemodbtype(cfile,...
    '/* External inputs (root inport signals with default storage) */',...
    '/* External outputs (root outports fed by signals with default storage) */',...
    1, 0);
%% Generate Code with |single| as Default Data Type
% Open the Configuration Parameters dialog box. 
% On the *Math and Data Types* pane, select |single| in the *Default
% for underspecified data type* drop-down list.
%
% Alternatively, enable the optimization at the command prompt.
set_param(model, 'DefaultUnderspecifiedDataType', 'single');
%%
% Generate code from the model.
rtwbuild(model)
%%
% In the code generation report, view the file
% |rtwdemo_underspecified_datatype.h|. The code uses the |single| data type
% to define the variables |In2|, |In3|, and |In4|.
rtwdemodbtype(cfile,...
    '/* External inputs (root inport signals with default storage) */',...
    '/* External outputs (root outports fed by signals with default storage) */',...
    1, 0);