function flag = isBERToolSimulationStopped()
%isBERToolSimulationStopped Simulation stop check for BERTool
%   S = isBERToolSimulationStopped returns false returns true if the
%   BERTool simulation has stopped. This function returns false, if the
%   BERTool simulation is running. 

%   Copyright 2020-2021 The MathWorks, Inc.

%#codegen

coder.extrinsic('evalin')

persistent count
if isempty(count)
  count = 1;
  if ~evalin('base','exist(''bertoolStoppedFlag'',''var'')')
    assignin('base','bertoolStoppedFlag',false);
  end
end

% Limit the calls to drawnow and evalin to every 100 calls
if ~mod(count,100)
  % Call drawnow to enable execution of GUI callbacks including the stop
  % button
  drawnow limitrate
  flag = evalin('base','bertoolStoppedFlag');
  count = 1;
else
  flag = false;
end

count = count + 1;
