[4] | 1 | function 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 | |
---|
| 18 | global THERING |
---|
| 19 | |
---|
| 20 | nb = length(ELEMPOS); % number of elements |
---|
| 21 | |
---|
| 22 | if 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 |
---|
| 32 | elseif 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 |
---|
| 44 | else % Error |
---|
| 45 | error('Wrong arguments'); |
---|
| 46 | end |
---|