function  createCopyCGVModel(obj)
%

%   Copyright 2010-2011 The MathWorks, Inc.
    % @todo update the usage of edit-time filter filterOutCodeInactiveVariantSubsystemChoices()
    % instead use the post-compile filter codeCompileVariants() - g2604228
    [~, mdlBlks] = find_mdlrefs(obj.Model,'MatchFilter',@Simulink.match.internal.filterOutCodeInactiveVariantSubsystemChoices, 'AllLevels', false ); % look only inside code active choice of VSS
    if ~isempty(mdlBlks) 
        obj.handleMsg('error', message('Sldv:RunTestCaseCGV:UnabletoCreateCopyModelBecauseModelRef', obj.Model));   
    end

    opts = sldvdefaultoptions;       
    opts.OutputDir = obj.OutputDir;
    
    FilePathCGVConfiguredModel = '$ModelName$_cgv';
    MakeOutputFilesUnique = get(opts,'MakeOutputFilesUnique');
    
    if strcmp(obj.UtilityName,'sldvruncgvtest')
        dialogTitle = getString(message('Sldv:RunTestCaseCGV:SimulinkDesignVerifier'));
    else
        dialogTitle = getString(message('Sldv:RunTestCase:SimulinkCoverage'));
    end

    objModelH = get_param(obj.Model,'Handle');
    
    fullPath = Sldv.utils.settingsFilename(...
        FilePathCGVConfiguredModel,...
        MakeOutputFilesUnique,...
        '$ModelExt$', objModelH, false, true, opts, dialogTitle);
    
    if isempty(fullPath)                                                                   
        obj.handleMsg('error', message('Sldv:RunTestCaseCGV:UnabletoCreateCopyModelForCGV', obj.Model));          
    end
    
    [copymodeldir, copymodel] = fileparts(fullPath); 
    copymodel  = sldvshareprivate('cmd_check_for_open_models', copymodel, MakeOutputFilesUnique, false);
    if isempty(copymodel)
        obj.handleMsg('error', message('Sldv:RunTestCaseCGV:UnabletoCreateCopyModelForCGV', obj.Model));        
    end
    
    copymodelFullPath = fullPath;
    
    originalmdlfileName = which(obj.Model); 
    copyfile(originalmdlfileName,copymodelFullPath);
    
    status = fileattrib(copymodelFullPath,'+w');        
    if ~status                
        obj.handleMsg('error', message('Sldv:RunTestCaseCGV:UnabletoCreateCopyModelForCGV', obj.Model));        
    end
    
    try
        Sldv.load_system(copymodelFullPath);
    catch Mex
        obj.handleMsg('error', message('Sldv:RunTestCaseCGV:UnabletoCreateCopyModelForCGV1', obj.Model, Mex.message));         
    end       
    
    obj.CGVModelH = get_param(copymodel,'Handle'); 
    obj.CGVModel = get_param(copymodel,'Name'); 
    obj.CGVModelPath = copymodelFullPath;    
    obj.CGVFullOutputDir = copymodeldir;
    
    % Check whether the copy model compiles
    addpath(copymodeldir);
    try
        evalc('feval(copymodel,[],[],[],''compileForSizes'');');        
        evalc('feval(copymodel,[],[],[],''term'');'); 
    catch Mex
        rmpath(copymodeldir);
        obj.handleMsg('error', message('Sldv:RunTestCaseCGV:UnabletoCreateCopyModelForCGV1', obj.Model, Mex.message));  
    end        
    rmpath(copymodeldir);        
end

% LocalWords:  CGV Unableto cgv Beause copymodel
