Home > pubtools > LatticeTuningFunctions > correction > tune > fittunedelta2fam.m

fittunedelta2fam

PURPOSE ^

rerr=fittunedelta2fam(rerr,r0)

SYNOPSIS ^

function rerr=fittunedelta2fam(rerr,r0)

DESCRIPTION ^

 rerr=fittunedelta2fam(rerr,r0)
 
 matches the tune of rerr to that of r0. 

 the 2 quadrupoles families used to correct the tune are marked by field:
 qfidx=findcells(rerr,'ForTuneF');
 qdidx=findcells(rerr,'ForTuneD');
 
 if atfittune fails a second attempt is made using atmatchtunedelta

see also: atfittune atmatchtunedelta

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rerr=fittunedelta2fam(rerr,r0)
0002 % rerr=fittunedelta2fam(rerr,r0)
0003 %
0004 % matches the tune of rerr to that of r0.
0005 %
0006 % the 2 quadrupoles families used to correct the tune are marked by field:
0007 % qfidx=findcells(rerr,'ForTuneF');
0008 % qdidx=findcells(rerr,'ForTuneD');
0009 %
0010 % if atfittune fails a second attempt is made using atmatchtunedelta
0011 %
0012 %see also: atfittune atmatchtunedelta
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;% inital tune lattice
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 % % match also integer part of the tune
0030 % disp(['Going to tune: ' num2str(t0+(te-WPtune)*0.5,'%2.5f, ')]);
0031 %
0032 % rerr=atmatchtunedelta(rerr,t0+(te-WPtune)*0.5,{qfidx, qdidx});
0033 %
0034 % [b]=atlinopt(rerr,0,1:length(rerr)+1);
0035 % ti=b(end).mu/2/pi;
0036 % disp(['Intermediate tune: ' num2str(ti,'%2.5f, ')]);
0037 %
0038 % rerr=atmatchtunedelta(rerr,WPtune,{qfidx, qdidx});
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 %if ~isempty(find((tf-t0)>=0.1,1)) || isnan(tf)
0051 %    disp('Corrected tune is >0.1 far from nominal')
0052     rerr=atmatchtunedelta(rerr,WPtune,{qfidx, qdidx});
0053 %end
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

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005