function out_filename = save_system(varargin)
%SAVE_SYSTEM Save a Simulink system.
%   SAVE_SYSTEM saves the current top-level system to a file with its
%   current name.
%
%   SAVE_SYSTEM('SYS') saves the specified top-level system to a file with
%   its current name.  The system must be currently open.
%     SYS can be a string, a cell array of strings, a numeric handle, or
%     an array of numeric handles.
%
%   SAVE_SYSTEM('SYS','NEWNAME') saves the specified top-level system to a
%   file with the specified new name.  The system must be currently open.
%   NEWNAME can be empty, in which case the current name is used.
%     If SYS refers to more than one block diagram, NEWNAME must be a cell
%     array of new names.
%
%   Additional arguments must be supplied as name-value pairs after the NEWNAME
%   argument (which can be empty).  Allowed names are:
%     ErrorIfShadowed: true or false (default: false)
%     BreakUserLinks: true or false (default: false)
%     OverwriteIfChangedOnDisk: true or false (default: false)
%     SaveModelWorkspace: true or false (default: false)
% The same options are applied to all the block diagrams which are saved.
% Options are case-insensitive on all platforms.
%
% SAVE_SYSTEM returns the full name of the file which was saved, as a string.
% If multiple files were saved, the return value is a cell array of strings.
%
% Examples:
%   save_system('mymodel')
%   save_system('mymodel','mynewmodel')
%   save_system('mymodel','','OverwriteIfChangedOnDisk',true)

%   Copyright 1996-2018 The MathWorks, Inc.

% Prevent editor UI events (ex: MouseMoveEvent) from getting processed during save callbacks, g1750126
scopedMessageBlocker = [];
if ~isempty(bdroot) && get_param(bdroot, 'open') == "on"
    scopedMessageBlocker = feval('SLM3I.ScopedGLIMMessageBlocker'); % feval to avoid load on file parse
end

if nargin
    filename = slInternal('save_system',varargin{:});
else
    filename = slInternal('save_system',bdroot);
end
delete(scopedMessageBlocker);

if nargout
    out_filename = filename;
end


