source: MML/trunk/machine/SOLEIL/Booster/applications/drawlattice_alex.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: 5.4 KB
Line 
1function drawlattice(Offset, Scaling)
2%DRAWLATTICE - Draws the AT lattice to a figure
3%  drawlattice(Offset, Scaling)
4
5%
6%  Written by Gregory J. Portmann
7%  Modified by Laurent S. Nadolski, SOLEIL, 03/09/04
8
9if nargin < 1
10    Offset = 0;
11end
12Offset = Offset(1);
13if nargin < 2
14    Scaling = 1;
15end
16Scaling = Scaling(1);
17
18global THERING
19
20SPositions = findspos(THERING, 1:length(THERING)+1);
21L = SPositions(end);
22plot([0 L], [0 0]+Offset, 'k');
23
24% Remember the hold state then turn hold on
25HoldState = ishold;
26hold on;
27
28% Make default icons for elements of different physical types
29for i = 1:length(THERING)
30    SPos = SPositions(i);
31    if isfield(THERING{i},'BendingAngle') && THERING{i}.BendingAngle
32        % make icons for bending magnets
33        IconHeight = .3;
34        IconColor = [1 0 0];
35        IconWidth = THERING{i}.Length;
36        if IconWidth < .15 % meters
37            IconWidth = .15;
38            SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
39        end
40        vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
41        vy = [IconHeight IconHeight -IconHeight -IconHeight];
42        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-');
43        %if IconWidth < .1 % meters
44        %    set(h, 'EdgeColor', IconColor);
45        %end
46
47    elseif isfield(THERING{i},'K') & THERING{i}.K
48        % Quadrupole
49        if THERING{i}.K > 0
50            % Focusing quadrupole
51            IconHeight = .6;
52            IconColor = [0 0 1];
53            IconWidth = THERING{i}.Length;
54            if IconWidth < .15 % meters
55                IconWidth = .15;
56                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
57            end
58            vx = [SPos SPos+IconWidth/2  SPos+IconWidth SPos+IconWidth/2 SPos];
59            vy = [0          IconHeight               0      -IconHeight    0];
60        else
61            % Defocusing quadrupole
62            IconHeight = .6;
63            IconColor = [0 0 1];
64            IconWidth = THERING{i}.Length;
65            if IconWidth < .15 % meters
66                IconWidth = .15;
67                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
68            end
69            vx = [SPos+.4*IconWidth    SPos    SPos+IconWidth  SPos+.6*IconWidth  SPos+IconWidth    SPos      SPos+.4*IconWidth];
70            vy = [     0            IconHeight   IconHeight          0              -IconHeight  -IconHeight    0];
71        end
72        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-');
73        %if IconWidth < .1 % meters
74        %    set(h, 'EdgeColor', IconColor);
75        %end
76
77%     elseif isfield(THERING{i},'PolynomB') & length(THERING{i}.PolynomB)>2 & THERING{i}.PolynomB(3)
78%         % Sextupole
79%         if THERING{i}.PolynomB(3)>0
80%             % Focusing sextupole
81%             IconHeight = .5;
82%             IconColor = [1 0 1];
83%             IconWidth = THERING{i}.Length;
84%             if IconWidth < .1 % meters
85%                 IconWidth = .1;
86%                 SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
87%             end
88%             vx = [SPos          SPos+.33*IconWidth  SPos+.66*IconWidth  SPos+IconWidth   SPos+IconWidth   SPos+.66*IconWidth  SPos+.33*IconWidth      SPos          SPos];
89%             vy = [IconHeight/3      IconHeight          IconHeight        IconHeight/3    -IconHeight/3      -IconHeight          -IconHeight     -IconHeight/3  IconHeight/3];
90%         else
91%             % Defocusing sextupole
92%             IconHeight = .5;
93%             IconColor = [0 1 0];
94%             IconWidth = THERING{i}.Length;
95%             if IconWidth < .1 % meters
96%                 IconWidth = .1;
97%                 SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
98%             end
99%             vx = [SPos          SPos+.33*IconWidth  SPos+.66*IconWidth  SPos+IconWidth   SPos+IconWidth   SPos+.66*IconWidth  SPos+.33*IconWidth      SPos          SPos];
100%             vy = [IconHeight/3      IconHeight          IconHeight        IconHeight/3    -IconHeight/3      -IconHeight          -IconHeight     -IconHeight/3  IconHeight/3];
101%         end
102%         h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-');
103%         %if IconWidth < .1 % meters
104%         %    set(h, 'EdgeColor', IconColor);
105%         %end
106%
107%     elseif isfield(THERING{i},'Frequency') & isfield(THERING{i},'Voltage')
108%         % RF cavity
109%         IconColor = [1 0.5 0];
110%         plot(SPos, 0+Offset, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 4)
111%
112%     elseif strcmpi(THERING{i}.FamName,'BPM')
113%         % BPM
114%         IconColor = 'k';
115%         plot(SPos, 0+Offset, '.-', 'Color', IconColor)
116%         %plot(SPos, 0, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 1.5)
117%
118%     elseif any(strcmpi(THERING{i}.FamName,{'COR','XCOR','YCOR','HCOR','VCOR'})) | isfield(THERING{i},'KickAngle')
119%         % Corrector
120%         IconHeight = .8;
121%         IconColor = [0 0 0];
122%         vx = [SPos   SPos];
123%         vy = [-IconHeight IconHeight];
124%         %plot(vx, Scaling*vy+Offset, 'Color', IconColor);
125%         IconWidth = THERING{i}.Length;
126%         vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
127%         vy = [IconHeight IconHeight -IconHeight -IconHeight];
128%         h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle', '-');
129%         if IconWidth < .1 % meters
130%             set(h, 'EdgeColor', IconColor);
131%         end
132      end
133end
134
135
136% Leave the hold state as it was at the start
137if ~HoldState
138    hold off
139end
140xaxis([0 L]);XTick=[];
141yaxis([-3 3]);
Note: See TracBrowser for help on using the repository browser.