%% Extract Atomic Subsystem to New Model
% This example shows how to extract an atomic subsystem from a model and
% copy it to a new model using |slvnvextract|.

% Copyright 2020 The MathWorks, Inc.

%%
% Load the |sldemo_lct_bus| model.

modelName = 'slcoverage_lct_bus';
load_system(modelName);
load slcoverage_lct_data.mat

%%
% The |slcoverage_lct_bus| model has an S-Function. Build the S-Function by
% using  |legacy_code|.

def = legacy_code('initialize');
def.SFunctionName = 'slcoverage_sfun_counterbus';
def.OutputFcnSpec = 'void counterbusFcn(COUNTERBUS u1[1], int32 u2, COUNTERBUS y1[1], int32 y2[1])';
def.HeaderFiles   = {'counterbus.h'};
def.SourceFiles   = {'counterbus.c'};
def.Options.supportCoverage = true;
legacy_code('generate_for_sim', def);

%%
% Extract the slCounter subsystem from the model and copy it to a new
% model.

newModel = slvnvextract([modelName,'/slCounter'],true)