0001 function rerr=fittunedelta2fam(rerr,r0)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 disp('Tune Matching')
0015 [b]=atlinopt(r0,0,1:length(r0)+1);
0016 t0=b(end).mu/2/pi;
0017 disp(['Nominal tune: ' num2str(t0,'%2.5f, ')]);
0018 WPtune=t0;
0019
0020 qfidx=findcells(rerr,'ForTuneF');
0021 qdidx=findcells(rerr,'ForTuneD');
0022
0023 rerr0=rerr;
0024
0025 [b]=atlinopt(rerr,0,1:length(rerr)+1);
0026 te=b(end).mu/2/pi;
0027 disp(['Initial tune: ' num2str(te,'%2.5f, ')]);
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 disp(['Going to tune: ' num2str(t0,'%2.5f, ')]);
0043 rerr = atfittune(rerr,WPtune,qfidx,qdidx);
0044 rerr = atfittune(rerr,WPtune,qfidx,qdidx);
0045
0046 [b]=atlinopt(rerr,0,1:length(rerr)+1);
0047 tf=b(end).mu/2/pi;
0048 disp(['Final tune: ' num2str(tf,'%2.5f, ')]);
0049
0050
0051
0052 rerr=atmatchtunedelta(rerr,WPtune,{qfidx, qdidx});
0053
0054
0055
0056 if ~isempty(find(isnan(tf)==1,1))
0057 disp('Corrected tune is NaN')
0058 rerr=rerr0;
0059 error('Corrected tune is NaN')
0060 end
0061
0062 if ~isempty(find(imag(tf)~=0,1))
0063 disp('Corrected tune is not real')
0064 rerr=rerr0;
0065 error('Corrected tune is not real')
0066 end
0067
0068 if ~isempty(find((tf-t0)>=0.1,1))
0069 disp('Corrected tune is >0.1 far from nominal')
0070 rerr=rerr0;
0071 error('Corrected tune is >0.1 far from nominal')
0072 end
0073
0074 end