source: MML/trunk/at/lattice/mvelem.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 1.7 KB
Line 
1function mvelem(ELEMPOS, DIST)
2%MVELEM(ELEMPOS, DIST) moves an element  located at ELEMPOS in THERING
3% surrounded by two DRIFT spaces
4%
5%  0   < DIST  < LD move downstream
6% -LU  < DIST  < 0  move upstream
7%  where LU and LD - lenths of
8%  upstream and downstrem drift drifts BEFORE!!! the move
9%
10% Number of elements in THERING and total length remain the same
11%
12% See also: SPLITDRIFT, MERGEDRIFT
13
14%
15% Modifications Laurent S. Nadolski
16% Add Vectorial form
17
18global THERING
19
20nb = length(ELEMPOS); % number of elements
21
22if nb == 1
23    L0 = THERING{ELEMPOS-1}.Length + THERING{ELEMPOS}.Length + THERING{ELEMPOS+1}.Length;
24    if DIST > THERING{ELEMPOS+1}.Length
25        error('Cannot move downstream more than the length of downstream drift');
26    elseif -DIST > THERING{ELEMPOS-1}.Length
27        error('Cannot move upstream more than the length of upstream drift');
28    else
29        THERING{ELEMPOS+1}.Length = THERING{ELEMPOS+1}.Length - DIST;
30        THERING{ELEMPOS-1}.Length = THERING{ELEMPOS-1}.Length + DIST;
31    end
32elseif nb > 1
33    for ik = 1:nb
34        L0 = THERING{ELEMPOS(ik)-1}.Length + THERING{ELEMPOS(ik)}.Length + THERING{ELEMPOS(ik)+1}.Length;
35        if DIST(ik) > THERING{ELEMPOS(ik)+1}.Length
36            error('Cannot move downstream more than the length of downstream drift');
37        elseif -DIST(ik) > THERING{ELEMPOS(ik)-1}.Length
38            error('Cannot move upstream more than the length of upstream drift');
39        else
40            THERING{ELEMPOS(ik)+1}.Length = THERING{ELEMPOS(ik)+1}.Length - DIST(ik);
41            THERING{ELEMPOS(ik)-1}.Length = THERING{ELEMPOS(ik)-1}.Length + DIST(ik);
42        end
43    end
44else % Error
45    error('Wrong arguments');
46end
Note: See TracBrowser for help on using the repository browser.