1 | function [s2 bx2 bz2 etax2 etaz2 ax2 az2] = tracy_readtwiss(file,cell) |
---|
2 | %function tracy_readtwiss(file,cell) - Plot Twiss functions from TRacy output file |
---|
3 | % |
---|
4 | % OUPUTS |
---|
5 | % 1. s2 - s-position alon the ring |
---|
6 | % 2. bx2 - Horizontal beta function |
---|
7 | % 3. bz2 - Vertical beta function |
---|
8 | % 4. etax2 - Horizontal dispersion |
---|
9 | % 5. etaz2 - Vertical dispersion |
---|
10 | % 6. ax2 - Horizontal alpha function |
---|
11 | % 7. az2 - Vertical alpha function |
---|
12 | % |
---|
13 | % cell = 1 show all the ring |
---|
14 | % cell = 4 show one out of 4 periods |
---|
15 | |
---|
16 | % |
---|
17 | %% Written by Laurent S. Nadolski, 27/09/08, SOLEIL |
---|
18 | |
---|
19 | DisplayFlag = 0; |
---|
20 | |
---|
21 | if nargin == 0 |
---|
22 | file = 'linlat.out'; |
---|
23 | end |
---|
24 | |
---|
25 | if (nargin ==2 && ~isempty(cell)) |
---|
26 | cell = 4; |
---|
27 | else |
---|
28 | cell = 1; |
---|
29 | end |
---|
30 | |
---|
31 | [dummy s ax bx mux etax etaxp az bz muz etaz etazp] = ... |
---|
32 | textread(file,'%s %f %f %f %f %f %f %f %f %f %f %f','headerlines',4); |
---|
33 | [s2 idx] = unique(s); |
---|
34 | ax2 = ax(idx); az2 = az(idx); |
---|
35 | bx2 = bx(idx); bz2 = bz(idx); |
---|
36 | etax2 = etax(idx); etaz2 = etaz(idx); |
---|
37 | %% |
---|
38 | if DisplayFlag |
---|
39 | h = figure(21) |
---|
40 | cla |
---|
41 | plot(s,bx,'r-',s,bz,'b-'); |
---|
42 | hold on; |
---|
43 | plot(s,10*etax,'g-',s,10*etaz,'k--') |
---|
44 | drawlattice(0,2,gca) |
---|
45 | %plotlattice(0,2) |
---|
46 | legend('\beta_x','\beta_z','10\eta_x','10\eta_z') |
---|
47 | xaxis([0 s(end)/cell]) |
---|
48 | title('Optical functions') |
---|
49 | xlabel('s (m)') |
---|
50 | datalabel on |
---|
51 | %% |
---|
52 | %% interpolation |
---|
53 | si = (s2(1):0.2:s2(end))'; |
---|
54 | bxi = interp1(s2,bx2,si,'pchip'); |
---|
55 | bzi = interp1(s2,bz2,si,'pchip'); |
---|
56 | etaxi = interp1(s2,etax2,si,'pchip'); |
---|
57 | etazi = interp1(s2,etaz2,si,'pchip'); |
---|
58 | |
---|
59 | figure(22) |
---|
60 | cla |
---|
61 | hold on; |
---|
62 | plot(si,bxi,'r-',si,bzi,'b-'); |
---|
63 | plot(si,10*etaxi,'g-',si,10*etazi,'k--') |
---|
64 | drawlattice(0,2,gca) |
---|
65 | legend('\beta_x','\beta_z','10\eta_x','10\eta_z') |
---|
66 | xaxis([0 s(end)/cell]) |
---|
67 | title('Optical functions') |
---|
68 | xlabel('s (m)') |
---|
69 | end |
---|