function ds = getParamNames(modelNames, blockNames, varargin)
% Copyright 2009 The MathWorks, Inc.
% Examples:
% ds = getParamNames('Flutter','BACT Wing & PAPA Mount')
% ds = getParamNames({'Flutter','FlutterSuppression'},{'BACT Wing & PAPA Mount'})
%
% See also
%% Check Inputs
% check if inputs are cell arrays
if ischar(modelNames)
modelNames = {modelNames};
end
if ischar(blockNames)
blockNames = {blockNames};
end
if ~iscell(modelNames) || ~iscell(blockNames)
% if not, then check if they are char arrays
error('getVarNames:WrongInput','Input modelNames or blockNames must be a cell array');
end
%% Open Model if Needed
% check if model is open, if not open it invisibly
slOpen = modelNames(~ismember(modelNames,find_system));
for i = 1:length(slOpen)
load_system(slOpen{i});
end
%% Set Defaults
wkspace = 'caller';
ds = dataset;
Units = {};
%% Get Block Variables
for m = 1:length(modelNames)
for b = 1:length(blockNames)
% create object reference
obj = [modelNames{m},'/',blockNames{b}];
% check to see if there is a mask and get parameters
if strcmpi(get_param(obj,'Mask'),'on');
bdp = get_param(obj,'DialogParameters');
else % no mask, so set value
bdp.value = get_param(obj,'value');
%error('getVarNames:MaskBlockNotFound',...
% 'Block %s does not have a mask',obj);
end %if
% get variable names
bvn = fieldnames(bdp);
vn = bvn;
% check to make sure vars are not in dataset array ds already
idx = ismember(bvn, ds.Properties.VarNames);
for v = 1:length(bvn)
if strcmpi(bvn{v},'value')
val = bdp.value;
vn{v} = get_param(obj,'name');
else
val = get_param(obj,bvn{v});
end
% append model number to it if different
if idx(v)
vn{v} = [bvn{v},num2str(m)];
end
if ischar(val)
% val is either an expression or a variable name and should
% be evaluated in the caller workspace if model is already
% open
ds.(vn{v}) = evalin(wkspace,val);
else
ds.(vn{v}) = val; % add variable name and value
end
if strcmpi(bvn{v},'value')
Units = [Units, {[obj,':',bvn{v},':none specified']}];
else
Units = [Units, {[obj,':',bvn{v},':',bdp.(bvn{v}).Prompt]}];
end
end
end %blockNames
end %modelName
%% Update Dataset Array
ds.Properties.Units = Units;
ds.Properties.UserData = nominal(repmat({'slParam'},size(Units)));
ds.Properties.ObsNames = 'Initial';