SPLITDRIFT inserts an element into a drift space SPLITDRIFT(DRIFTPOS, SPLIT) inserts a marker (zero-length) element at distance SPLIT ( 0 < SPLIT < 1) into a drift space located at DRIFTPOS in THERING SPLITDRIFT(DRIFTPOS, SPLIT, ELEMSTRUCCTURE) inserts a marker (zero-length) element at distance SPLIT ( 0 < SPLIT < 1) into a drift space located at DRIFTPOS in THERING Number of elements in the RING is thus increased by 2 SPLIT (controls the position of the split L1 = L0*SPLIT L2 = L0(1-SPLIT) where L0 is the length of the original DRIFT See also: MERGEDRIFT
0001 function splitdrift(DRIFTPOS, SPLIT, varargin) 0002 %SPLITDRIFT inserts an element into a drift space 0003 % 0004 % SPLITDRIFT(DRIFTPOS, SPLIT) inserts a marker (zero-length) element 0005 % at distance SPLIT ( 0 < SPLIT < 1) into a drift space 0006 % located at DRIFTPOS in THERING 0007 % 0008 % SPLITDRIFT(DRIFTPOS, SPLIT, ELEMSTRUCCTURE) inserts a marker (zero-length) element 0009 % at distance SPLIT ( 0 < SPLIT < 1) into a drift space 0010 % located at DRIFTPOS in THERING 0011 % 0012 % Number of elements in the RING is thus increased by 2 0013 % SPLIT (controls the position of the split 0014 % L1 = L0*SPLIT 0015 % L2 = L0(1-SPLIT) 0016 % where L0 is the length of the original DRIFT 0017 % 0018 % See also: MERGEDRIFT 0019 0020 global THERING 0021 0022 N0 = length(THERING); % number of elements in THERING before split 0023 0024 L0 = THERING{DRIFTPOS}.Length; 0025 if (SPLIT < 0 | SPLIT >1) 0026 error('Second argument must be (0..1)'); 0027 else 0028 if nargin == 2 0029 for i = reverse(DRIFTPOS:N0) 0030 THERING{i+2} = THERING{i}; 0031 end 0032 THERING{DRIFTPOS}.Length = L0*SPLIT; 0033 THERING{DRIFTPOS+2}.Length = L0*(1-SPLIT); 0034 THERING{DRIFTPOS+1} = struct('FamName','TEMPSPLIT', 'Length', 0, 'PassMethod','IdentityPass'); 0035 elseif isstruct(varargin{1}) 0036 % Check if a new element will fit 0037 if L0*(1-SPLIT) >= varargin{1}.Length 0038 for i = reverse(DRIFTPOS:N0) 0039 THERING{i+2} = THERING{i}; 0040 end 0041 THERING{DRIFTPOS}.Length = L0*SPLIT; 0042 THERING{DRIFTPOS+2}.Length = L0*(1-SPLIT)-varargin{1}.Length; 0043 THERING{DRIFTPOS+1} = varargin{1}; 0044 else 0045 error('The inserted element is too long'); 0046 end 0047 end 0048 0049 end