Home > lattice > rmelem0.m

rmelem0

PURPOSE ^

RMELEM0 removes elements of length 0 from the accelerator lattice

SYNOPSIS ^

function [NEWLATTICE, SHIFTEDINDEX] = rmelem0(LATTICE,ELEMINDEX)

DESCRIPTION ^

RMELEM0 removes elements of length 0 from the accelerator lattice
 NEWLATTICE = RMELEM0(LATTICE,ELEMINDEX)
 [NEWLATTICE, SHIFTEDINDEX] = RMELEM0(LATTICE,ELEMINDEX)

 The number of elements in the modified lattice is 
 reduced by length(ELEMINDEX)

 SHIFTEDINDEX points to elements in the NEWLATTICE that
 immediateley followed the removed elements in the original LATTICE

 See also: SPLITDRIFT MERGEDRIFT

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [NEWLATTICE, SHIFTEDINDEX] = rmelem0(LATTICE,ELEMINDEX) 
0002 %RMELEM0 removes elements of length 0 from the accelerator lattice
0003 % NEWLATTICE = RMELEM0(LATTICE,ELEMINDEX)
0004 % [NEWLATTICE, SHIFTEDINDEX] = RMELEM0(LATTICE,ELEMINDEX)
0005 %
0006 % The number of elements in the modified lattice is
0007 % reduced by length(ELEMINDEX)
0008 %
0009 % SHIFTEDINDEX points to elements in the NEWLATTICE that
0010 % immediateley followed the removed elements in the original LATTICE
0011 %
0012 % See also: SPLITDRIFT MERGEDRIFT
0013 
0014 % make a new (empty) lattice
0015 OLDN = length(LATTICE);
0016 NEWN = OLDN-length(ELEMINDEX);
0017 
0018 THERING = cell(1,NEWN);
0019 NEWINDEX = zeros(size(ELEMINDEX));
0020 
0021 ALLELEMS = 1:length(LATTICE);
0022 ALLELEMS(ELEMINDEX)=0;
0023 NZ = find(ALLELEMS);
0024 
0025 for i = 1:length(NZ)
0026     NEWLATTICE{i}=LATTICE{NZ(i)};
0027 end
0028 
0029 
0030 % current warning state
0031 originalwarnstate = warning;
0032 warning off backtrace
0033 
0034     newlength=findspos(NEWLATTICE,NEWN+1);
0035     oldlength=findspos(LATTICE,OLDN+1);
0036     if newlength~=oldlength
0037         error('Elements to be removed must have 0 physical length');
0038     end
0039 
0040     SHIFTEDINDEX = 1+(ELEMINDEX(:)-(1:length(ELEMINDEX))');
0041     if size(SHIFTEDINDEX)~=size(ELEMINDEX)
0042         SHIFTEDINDEX=SHIFTEDINDEX';
0043     end
0044     if ELEMINDEX(end)==OLDN
0045         warning('Last element in the original LATTICE was removed');
0046     end
0047 
0048     i = 1;
0049     while i<=length(ELEMINDEX)
0050         if ~strcmp(LATTICE{ELEMINDEX(i)}.PassMethod,'IdentityPass')
0051             warning('One or more removed elements used PassMethod other than ''IdentityPass''!');
0052             i = length(ELEMINDEX)+1;
0053         else
0054             i=i+1;
0055         end
0056     end
0057     warning(originalwarnstate);

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