function sldvharnessinit(varargin)
%SLDVHARNESSINIT - Helper utility for initializing parameters

%   Copyright 2006-2018 The MathWorks, Inc.

% Example
%
% sldvharnessinit(3,'control_mode=1;',1,'control_mode=2');
%

    modelName = gcs;
    modelH = get_param(modelName, 'Handle');
    harnessSource = Sldv.harnesssource.Source.getSource(modelH);

    if isempty(harnessSource)
        return;
    end

    actTcIdx = harnessSource.getActiveTestcase;

    allTestCnts = [varargin{1:2:end}];
    allInitCmds = {varargin{2:2:end}};

    testThreshold = cumsum(allTestCnts);
    
    if actTcIdx<=testThreshold(1)
        origMdlIdx=1;
    else
        origMdlIdx = find(actTcIdx>testThreshold);
        if isempty(origMdlIdx)
            return;
        end
        origMdlIdx = origMdlIdx+1;
    end

    origMdlIdx = origMdlIdx(end);

    if origMdlIdx>length(allInitCmds)
        return;
    end

    initCmd = allInitCmds{origMdlIdx};
    
    if ~isempty(initCmd)
        evalin('base',initCmd);
    end
