Home > lattice > combinelinear45.m

combinelinear45

PURPOSE ^

COMBINELINEAR45 combines adjacent elements that use 4-by-5 PassMethods

SYNOPSIS ^

function [NEWLATTICE, SHIFTEDKEEPINDEX, SHIFTEDREFINDEX] = combinelinear45(LATTICE,KEEPINDEX,REFINDEX)

DESCRIPTION ^

COMBINELINEAR45 combines adjacent  elements that use 4-by-5 PassMethods
 [NEWLATTICE, SHIFTEDKEEPINDEX, SHIFTEDREF] = COMBINELINEAR45(LATTICE,KEEPINDEX,REFINDEX)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [NEWLATTICE, SHIFTEDKEEPINDEX, SHIFTEDREFINDEX] = combinelinear45(LATTICE,KEEPINDEX,REFINDEX) 
0002 %COMBINELINEAR45 combines adjacent  elements that use 4-by-5 PassMethods
0003 % [NEWLATTICE, SHIFTEDKEEPINDEX, SHIFTEDREF] = COMBINELINEAR45(LATTICE,KEEPINDEX,REFINDEX)
0004 
0005 
0006 % make a new (empty) lattice
0007 OLDN = length(LATTICE);
0008 
0009 I45 = findcells(LATTICE,'PassMethod','Linear45Pass');
0010 
0011 D = diff(I45);
0012 
0013 A = 1:length(LATTICE);
0014 A(I45(find(~(D-1))))=0;
0015 
0016 A = ~A;
0017 
0018 % A has been constructed such that if
0019 %  A(i)=1 , LATTICE{i} should be combined with LATTICE{i+1}
0020 
0021 
0022 if ~isempty(KEEPINDEX)
0023     A(KEEPINDEX)=0;
0024     K = KEEPINDEX-1;
0025     if K(1)<1
0026         A(K(2:end))=0;
0027     else
0028         A(K)=0;
0029     end
0030 else
0031     SHIFTEDKEEPINDEX = [];
0032 end
0033 
0034 if ~isempty(REFINDEX)
0035     R = REFINDEX-1;
0036     if R(1)<1
0037         A(R(2:end))=0;
0038     else
0039         A(R)=0;
0040     end
0041 else
0042     SHIFTEDREFINDEX = [];
0043 end
0044 
0045 CSA = cumsum(A);
0046 
0047 SHIFTEDKEEPINDEX = KEEPINDEX-CSA(KEEPINDEX);
0048 
0049 if ~isempty(REFINDEX)
0050     if REFINDEX(1)<2
0051         SHIFTEDREFINDEX = REFINDEX-[0 CSA(REFINDEX(2:end)-1)];
0052     else
0053         SHIFTEDREFINDEX = REFINDEX-CSA(R);
0054     end
0055 end
0056 
0057 
0058 SHIFTEDREFINDEX = REFINDEX-CSA(REFINDEX-1) ;
0059 
0060 
0061 NEWN = CSA(end);
0062 NEWLATTICE = cell(1,NEWN);
0063 
0064 NEWLATTICE{1}=LATTICE{1};
0065 writepos = 1; 
0066 for i=2:OLDN
0067     if A(i-1)
0068         NEWLATTICE{writepos}.M45 = LATTICE{i}.M45(:,1:4)*NEWLATTICE{writepos}.M45;
0069         NEWLATTICE{writepos}.M45(:,5)=NEWLATTICE{writepos}.M45(:,5)+LATTICE{i}.M45(:,5);
0070         NEWLATTICE{writepos}.Length = NEWLATTICE{writepos}.Length+LATTICE{i}.Length;
0071     else
0072         writepos = writepos+1;
0073         NEWLATTICE{writepos}=LATTICE{i};
0074     end
0075 end

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