function sys = ocset(varargin)
%OCSET Create/alter OCCDS data structure.
% SYS = OCSET('PARAM1',VALUE1,'PARAM2',VALUE2,...) creates a data
% structure SYS in which the named parameters have the specified values.
% Any unspecified parameters are set to the default value for that
% parameter.
%
% SYS = OCSET(OLDSYS,'PARAM1',VALUE1,...) creates a copy of OLDSYS
% with the named parameters altered with the specified values.
%
% SYS = OCSET(OLDSYS,NEWSYS) combines an existing options structure
% OLDSYS with a new options structure NEWSYS. Any parameters in NEWSYS
% with non-empty values overwrite the corresponding old parameters in
% OLDSYS.
%
% SYS = OCSET (with no input arguments) creates an options structure
% SYS where all the fields are set to the default.
%
%
%OCSET PARAMETERS for MATLAB
% Type - Indicates combination of open-closed PD controls
% 0: No control
% 1: open-closed P
% 2: open-closed PD (default)
% 3: open-closed D
% 4: closed P
% 5: closed PD
% 6: closed D
% 7: open-only
% Alpha - Structural value (default 10)
% Gamma - Damping constant (default 0.01)
% L - Length of beam (default 1)
% xo - Initial modal displacement vector (default 0)
% vo - Initial modal velocity vector (default 1)
% a - open loop parameter (default 0)
% b - open loop parameter (default 0)
% cp - closed loop P parameter (default 100)
% cd - closed loop D parameter (default 10)
% To - Terminal time (default 0.01)
% uu - Performance weight vector (default [1 1 1e-6 1e-6 1e-6])
% Ti - Initial time (default 0)
% IOL - Independent open loop control indicator
% 0: Dependent (default)
% 1: Independent
% T - Length of time delay (default 0)
%
% Note: To see OCSET parameters for the OPTIMIZATION TOOLBOX
% (if you have the Optimization Toolbox installed), type
% help optimoptions
%
% Examples
% To create options with the default options for fzero
% options = optimset('fzero');
% To create an options structure with TolFun equal to 1e-3
% options = optimset('TolFun',1e-3);
% To change the Display value of options to 'iter'
% options = optimset(options,'Display','iter');
%
if nargin>0 && isstruct(varargin{1})
% Use specified system
sys = varargin{1};
varargin = varargin(2:end);
else
% Create default system
sys=struct('Type',2,'Alpha',10,'Gamma',0.01,'xo',0,'vo',1,'a',0,'b',0,'cp',100,...
'cd',10,'To',0.01,'uu',[1 1 1e-6 1e-6 1e-6],'Ti',0,'IOL',0,'T',0,'L',1);
end
if nargin>1 && isstruct(varargin{1})
% Combine old with new
newsys = varargin{1};
flds = fieldnames(newsys);
vals = struct2cell(newsys);
for n=1:length(flds)
sys=setfield(sys,flds{n},vals{n});
end
elseif ~isempty(varargin) && mod(length(varargin),2)==0
for n = 1:2:length(varargin)-1
sys=setfield(sys,varargin{n},varargin{n+1});
end
end
% % Ensure column vector
% sys.a = sys.a(:);
% sys.b = sys.b(:);
% % Ensure row vector
% sys.xo = sys.vo(:).';
% sys.vo = sys.xo(:).';