Home > lattice > splitelem.m

splitelem

PURPOSE ^

INSERTELEM inserts one or more elements inside another element

SYNOPSIS ^

function elemseq = insertelem(ELEM, varargin)

DESCRIPTION ^

 INSERTELEM inserts one or more elements inside another element
  and returns the resulting sequence of elements  as a cell array
  ready to to be used in AT lattice

 ELEMSEQ = INSERTELEM(ELEM0, ELEM1, pos1, ... ELEMN, POSN, 'OPT1', .. 'OPTN')

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function elemseq = insertelem(ELEM, varargin)
0002 % INSERTELEM inserts one or more elements inside another element
0003 %  and returns the resulting sequence of elements  as a cell array
0004 %  ready to to be used in AT lattice
0005 %
0006 % ELEMSEQ = INSERTELEM(ELEM0, ELEM1, pos1, ... ELEMN, POSN, 'OPT1', .. 'OPTN')
0007 
0008 %
0009 % Use [] in place of an element to be inserted to only split ELEM0
0010 
0011  
0012 % % Optons control fields of elements that are created as a result of slicing
0013 %  options other than inserting into drift are NOT IMPLEMENTED YET - IN AT 1.3
0014 % 'inherit',  'FIELDNAMES', values of these fields are duplicated in new elements
0015 % 'slice',    'FILEDNAMES'  values are scaled by L/Lo
0016 % 'remove',    Fields are removed from all INNER elements
0017 %
0018 % 'removefirst'
0019 % 'removelast'
0020 %
0021 %
0022 % % Typical option sets
0023 % 'drift' - is the default option useful to insert elemenst inside a drift space
0024 % 'bend'
0025 % 'misalign'
0026 
0027 
0028 if ~isatelem(ELEM)
0029     error('The first argument must be a valid Accelerator Toolbox element');
0030 end
0031 
0032 % Parse arguments
0033 ELEMS2INSERT = {};
0034 
0035 POSITION = {};
0036 LENGTH = {};
0037 
0038 OPTIONSET = struct;
0039 
0040 k = 1;
0041 while k < nargin
0042     if isatelem(varargin{k})
0043         if ~k<nargin & ~isnumeric(varargin{k+1})
0044             errorstr = sprintf('Incorrect syntax:\n');
0045             errorstr=[errorstr,sprintf('Elements to be inserted must be followed by position\n')];
0046             errorstr=[errorstr,sprintf('in the argument list: ELEM1, pos1, ... ELEMN, POSN ')];
0047             error(errorstr);
0048         else
0049             ELEMS2INSERT{end+1} = varargin{k};
0050             k = k+2;
0051         end
0052     elseif ischar(varargin{k})
0053         switch lower(varargin{k})
0054             case 'drift'
0055                 OPTIONSET.inherit = {'FamName','PassMethod'};
0056                 OPTIONSET.slice = {'Length'};
0057                 OPTIONSET.removeinner = {};
0058                 OPTIONSET.removefirst = {};
0059                 OPTIONSET.removelast  = {};
0060             otherwise
0061                 error('Options other than drift are not yet implemented');
0062         end
0063     else
0064         error('Incorrect syntax');
0065     end
0066     
0067 end
0068 
0069 if isempty(OPTIONSET)
0070     %
0071     OPTIONSET.inherit = {'FamName','PassMethod'};
0072     OPTIONSET.slice = {'Length'};
0073     OPTIONSET.removeinner = {};
0074     OPTIONSET.removefirst = {};
0075     OPTIONSET.removelast  = {};
0076 % Check if lenghts and positions are consistent
0077 nelemins = length(ELEMS2INSERT);
0078 nelemnew = 1+2*ELEMS2INSERT;
0079 
0080 L0 = ELEM.Length;
0081 
0082 sp(1) = 0
0083 
0084 for k = 1:nelemins
0085 sposition( =

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