Home > lattice > atelem.m

atelem

PURPOSE ^

ATELEM makes a new AT element structure from another element,

SYNOPSIS ^

function elemstruct = atelem(elem,varargin)

DESCRIPTION ^

ATELEM makes a new AT element structure from another element,
 standard AT type, or a template on file. Existing fields are overridden
 with new values. New fields are added and initialized.

 NEWELEM = ATELEM(ELEM,'Field1','Value1','Field2', 'Value2', ...)
  ELEM can be 1) another element structure
              2) One of the standard AT types
                 'drift'
                 'quadrupole'
                 'sextupole'
                 'bend','rbend','sbend'
                 'marker'
                 'corrector'
                  ...

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function elemstruct = atelem(elem,varargin)
0002 %ATELEM makes a new AT element structure from another element,
0003 % standard AT type, or a template on file. Existing fields are overridden
0004 % with new values. New fields are added and initialized.
0005 %
0006 % NEWELEM = ATELEM(ELEM,'Field1','Value1','Field2', 'Value2', ...)
0007 %  ELEM can be 1) another element structure
0008 %              2) One of the standard AT types
0009 %                 'drift'
0010 %                 'quadrupole'
0011 %                 'sextupole'
0012 %                 'bend','rbend','sbend'
0013 %                 'marker'
0014 %                 'corrector'
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)) % Generic
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 % function that returns an at element structure
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

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005