function closeShellLibrary(libName)

% Load the library to get all block mask types
load_system(libName);
blocks = find_system(libName,'type','block');
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
      if ~isempty(find_system(open_bd(p), 'MaskType', maskTypes{q}))
        bdclose(open_bd{p});
        cnt = cnt + 1;
      end
    end
  end
end
end
