function closeShellLibrary(libName)
%

%   Copyright 2016-2021 The MathWorks, Inc.

% Load the library to get all block mask types
load_system(libName);
% @todo update the usage of edit-time filter filterOutInactiveVariantSubsystemChoices()
% instead use the post-compile filter activeVariants() - g2597271
blocks = find_system(libName,'MatchFilter',@Simulink.match.internal.filterOutInactiveVariantSubsystemChoices, 'type', 'block' ); % look only inside active choice of VSS
maskTypes = cell(size(blocks));
numBlocks = length(blocks);
for p=1:length(numBlocks)
  maskTypes{p} = get_param(blocks{p}, 'MaskType');
end

open_bd = find_system('type', 'block_diagram');
cnt = 1;
for p=1:length(open_bd)
  if strcmp(open_bd{p}, libName)
    bdclose(libName);
  else
    for q=1:numBlocks
      % @todo update the usage of edit-time filter filterOutInactiveVariantSubsystemChoices()
      % instead use the post-compile filter activeVariants() - g2597271
      if ~isempty(find_system(open_bd(p),'MatchFilter',@Simulink.match.internal.filterOutInactiveVariantSubsystemChoices, 'FirstResultOnly', 'on', 'MaskType', maskTypes{q}))
        bdclose(open_bd{p});
        cnt = cnt + 1;
      end
    end
  end
end
end
