function switchObsMdlsToStandaloneMode(modelH)
%SWITCHOBSMDLSTOSTANDALONE:
%     This API would convert all the observer models from contexted
%     to standalone mode which are present in given design model.
%     This is important because in case of model
%     references same observer models would have to be loaded sometimes in
%     the context of design model and sometimes in the context of
%     replacement models
%
% Assumption: This API assumes that all the observer model names passed as
%             input here are loaded in memory

%   Copyright 2020 The MathWorks, Inc.

% Sometimes callers would pass in modelName
    if ischar(modelH)
        try
            modelH = get_param(modelH,'Handle');
        catch Mex %#ok<NASGU>
            return;
        end
    end

    obsRefBlks = Simulink.observer.internal.getObserverRefBlocksInBD(modelH);

    for i = 1 : numel(obsRefBlks)
        obsMdlName = get_param(obsRefBlks(i), 'ObserverModelName');

        obsMdlH = get_param(obsMdlName, 'Handle');

        try
            if ~isequal(Simulink.observer.internal.getContextForBlockInObsMdl(obsMdlH), -1)
                Simulink.sltblkmap.internal.convertContextedMdlToStandalone(obsMdlH, obsRefBlks(i));
            end
        catch ME
            Simulink.observer.internal.error(ME, true, 'Simulink:Observer:ObserverStage', obsMdlName);
            return;
        end
    end

end
