0001 function elemstruct = atelem(elem,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 if isstruct(elem)
0018 elemstruct = elem;
0019 for k=1:2:length(varargin)
0020 NextField = (varargin{k});
0021 if ischar(NextField)
0022 elemstruct.(NextField) = varargin{k+1};
0023 else
0024 error('Field and value input arguments must come in pairs');
0025 end
0026 end
0027 elseif ischar(elem)
0028 switch lower(elem(1:4))
0029 case 'drif'
0030 elemstruct=atdrift('',varargin{:});
0031 case 'quad'
0032 elemstruct=atquadrupole('',varargin{:});
0033 case 'sext'
0034 elemstruct=atsextupole('',varargin{:});
0035 case 'mark'
0036 elemstruct=atmarker('',varargin{:});
0037 case {'bend','sben'}
0038 elemstruct=atsbend('',varargin{:});
0039 case 'rben'
0040 elemstruct=atrbend('',varargin{:});
0041 case 'corr'
0042 elemstruct=atcorrector('',varargin{:});
0043 otherwise
0044 error('AT:atelem:UnknownType',['Unknown element type: ' elem]);
0045 end
0046 else
0047 error('First argument must be an AT element or a string keyword')
0048 end