1 | function [nux,nuy, delta]=fmap_nudp(ndp,deltamax) |
---|
2 | % fmap_nudp(ndp,deltamax) - Compute tuneshift with energy |
---|
3 | % |
---|
4 | % Routine's out of Andrei Terebilos ATtoolbox and |
---|
5 | % Jacques Laskars NAFF algorithm |
---|
6 | % (calcnaff.mex or calcnaff.dll) |
---|
7 | % |
---|
8 | % INPUTS |
---|
9 | % 1. ndp number of horizontal amplitudes |
---|
10 | % 2. deltmax number of vertical amplitudes |
---|
11 | % |
---|
12 | % OUTPUTS |
---|
13 | % 1. nux horizontal betatron tune |
---|
14 | % 2. nuy vertical betatron tune |
---|
15 | % 3. delta energy offset |
---|
16 | |
---|
17 | % |
---|
18 | % Laurent Nadolski, ALS 09/01/02 |
---|
19 | % Revised, April 22, 2011 |
---|
20 | |
---|
21 | DisplayFlag =1; |
---|
22 | global THERING |
---|
23 | |
---|
24 | radiationoff; |
---|
25 | cavityoff; |
---|
26 | |
---|
27 | %plotbeta; |
---|
28 | |
---|
29 | %fprintf('Type any key to continue ...\n'); |
---|
30 | %pause; |
---|
31 | |
---|
32 | NT = 1026; |
---|
33 | |
---|
34 | T = ringpass(THERING,[0;0;0;0;0;0],1); |
---|
35 | |
---|
36 | delta = (-ndp:1:ndp)*deltamax/ndp; |
---|
37 | |
---|
38 | for i=1:(2*ndp+1) |
---|
39 | %fprintf('amp_x=%g mm, amp_y=%g mm\n',ampx,ampy); |
---|
40 | cod = getcod(THERING,delta(i)); |
---|
41 | X0=[1e-6 0 1e-6 0 delta(i) 0]' + [cod(:,1); 0; 0] ; |
---|
42 | |
---|
43 | cpustart=cputime; |
---|
44 | [T LOSSFLAG] = ringpass(THERING,X0,NT,'reuse'); |
---|
45 | cpustop=cputime; |
---|
46 | fprintf('track time for %d turns : %g s\n', NT, cpustop-cpustart); |
---|
47 | |
---|
48 | Tx = T(1,:); Txp = T(2,:); |
---|
49 | Ty = T(3,:); Typ = T(4,:); |
---|
50 | TE = T(5,:); Tphi = T(6,:); |
---|
51 | |
---|
52 | if (length(Ty)==NT) & (all(Ty<0.004)) ... |
---|
53 | & (~any(isnan(Ty))) & (LOSSFLAG==0) |
---|
54 | |
---|
55 | cpustart = cputime; |
---|
56 | tmpnux1 = calcnaff(Tx(1:NT),Txp(1:NT),1); |
---|
57 | tmpnux1 = abs(tmpnux1/(2*pi)); |
---|
58 | tmpnuy1 = calcnaff(Ty(1:NT),Typ(1:NT),1); |
---|
59 | tmpnuy1 = abs(tmpnuy1/(2*pi)); |
---|
60 | |
---|
61 | cpustop=cputime; |
---|
62 | fprintf('NAFF CPU time (4*512 turns) : %g s\n',cpustop-cpustart); |
---|
63 | |
---|
64 | nux(i)=NaN; nuy(i) = NaN; |
---|
65 | |
---|
66 | if abs(tmpnux1(1)) > 1e-6 |
---|
67 | nux(i) = tmpnux1(1); |
---|
68 | else |
---|
69 | nux(i) = tmpnux1(2); |
---|
70 | end |
---|
71 | |
---|
72 | if abs(tmpnuy1(1)) > 1e-6 |
---|
73 | nuy(i) = tmpnuy1(1); |
---|
74 | else |
---|
75 | nuy(i) = tmpnuy1(2); |
---|
76 | end |
---|
77 | end |
---|
78 | end |
---|
79 | |
---|
80 | %% |
---|
81 | if DisplayFlag |
---|
82 | figure |
---|
83 | plot(delta*100, nux, 'b.'); |
---|
84 | hold on; |
---|
85 | plot(delta*100, nuy, 'r.'); |
---|
86 | ylabel('Fractional tune'); |
---|
87 | legend('H-tune', 'V-tune'); |
---|
88 | xlabel('Energy offset %)'); |
---|
89 | end |
---|