Home > pubtools > LatticeTuningFunctions > errors > setTiltAbout.m

setTiltAbout

PURPOSE ^

SYNOPSIS ^

function re=setTiltAbout(r,pos,coord,PSI)

DESCRIPTION ^


 update

see also: SETSHIFT_THERING settilt_THERING_Dipole

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function re=setTiltAbout(r,pos,coord,PSI)
0002 %
0003 %
0004 % update
0005 %
0006 %see also: SETSHIFT_THERING settilt_THERING_Dipole
0007 
0008 numelems = length(pos);
0009 
0010 if (numelems ~= length(PSI))
0011     error('ELEMINDEX, D must have the same number of elements');
0012 end
0013 
0014 b_s=1; % speed of electrons!
0015 
0016 additive=0;
0017 
0018 switch coord
0019     case 'y_MAD8'
0020         for i = 1:length(pos)
0021             
0022             C = cos(PSI);
0023             S = sin(PSI);
0024             T = tan(PSI);
0025             
0026             RM = diag([1 1  C(i) 1/C(i) 1  1 ]);
0027             RM(4,5) = -1/b_s*T(i);
0028             RM(1,6) = 1/b_s*S(i);
0029             
0030             r{pos(i)}.R1 = RM;
0031             r{pos(i)}.R2 = RM';
0032             r{pos(i)}.RotAboutY =   PSI(i);
0033          %   r{pos(i)}.Pitch =   PSI(i);
0034             
0035         end
0036     case 'x_MAD8'
0037         for i = 1:length(pos)% angle is changing!
0038             C = cos(PSI);
0039             S = sin(PSI);
0040             T = tan(PSI);
0041             
0042             RM = diag([ C(i) 1/C(i) 1 1 1  1 ]);
0043             RM(2,5) = -1/b_s*T(i);
0044             RM(1,6) = 1/b_s*S(i);
0045             
0046             r{pos(i)}.R1 = RM;
0047             r{pos(i)}.R2 = RM';
0048          
0049              r{pos(i)}.RotAboutX =   PSI(i);
0050        %     r{pos(i)}.Yaw =   PSI(i);
0051             
0052         end
0053         
0054     case 'y'
0055         for i = 1:length(pos)
0056             if additive
0057                 r{pos(i)}.T1(1,2) =  r{pos(i)}.T1(2)  -PSI(i);
0058                 r{pos(i)}.T2(1,2) = r{pos(i)}.T2(2)   +PSI(i);
0059                 r{pos(i)}.T1(1,1) =  r{pos(i)}.T1(1)  +r{pos(i)}.Length/2*sin(PSI(i));
0060                 r{pos(i)}.T2(1,1) =   r{pos(i)}.T2(1) +r{pos(i)}.Length/2*sin(PSI(i));
0061                 r{pos(i)}.RotAboutY = r{pos(i)}.RotAboutY +  PSI(i);
0062            %     r{pos(i)}.Pitch = r{pos(i)}.Pitch +  PSI(i);
0063                 %DS =+L/2(1-cos(psi) both in and out, ignored. (if including, do not change sign!)
0064             else
0065                 r{pos(i)}.T1(1,2) =   -PSI(i);
0066                 r{pos(i)}.T2(1,2) =   +PSI(i);
0067                 r{pos(i)}.T1(1,1) =   +r{pos(i)}.Length/2*tan(PSI(i));
0068                 r{pos(i)}.T2(1,1) =   +r{pos(i)}.Length/2*tan(PSI(i));
0069                 r{pos(i)}.RotAboutY =   PSI(i);
0070              %   r{pos(i)}.Pitch =   PSI(i);
0071                 %DS =+L/2(1-cos(psi) both in and out, ignored. (if including, do not change sign!)
0072             end
0073             
0074             % % reset error
0075 % r=atsetfieldvalues(r,ind,'T1',[0 0 0 0 0 0]);
0076 % r=atsetfieldvalues(r,ind,'T2',[0 0 0 0 0 0]);
0077 %
0078 % % rotate
0079 % r=setTiltAbout(r,ind,'x',rotval*ones(size(ind)));
0080 %
0081 % % displace
0082 % t1=atgetfieldvalues(r,ind,'T1',{1,1});
0083 % t2=atgetfieldvalues(r,ind,'T2',{1,1});
0084 %
0085 % r=atsetfieldvalues(r,ind,'T1',{1,1},t1-dispval/cos(rotval));
0086 % r=atsetfieldvalues(r,ind,'T2',{1,1},t2+dispval/cos(rotval));
0087 
0088             
0089         end
0090     case 'x'
0091         for i = 1:length(pos)
0092             if additive
0093                 r{pos(i)}.T1(1,4) = r{pos(i)}.T1(4)  -PSI(i);
0094                 r{pos(i)}.T2(1,4) = r{pos(i)}.T2(4)  +PSI(i);
0095                 r{pos(i)}.T1(1,3) = r{pos(i)}.T1(3)  +r{pos(i)}.Length/2*sin(PSI(i));
0096                 r{pos(i)}.T2(1,3) = r{pos(i)}.T2(3)  +r{pos(i)}.Length/2*sin(PSI(i));
0097                 r{pos(i)}.RotAboutX = r{pos(i)}.RotAboutX+  PSI(i);
0098           %      r{pos(i)}.Yaw = r{pos(i)}.Yaw+  PSI(i);
0099                 %DS =+L/2(1-cos(psi) both in and out, ignored. (if including, do not change sign!)
0100             else
0101                 r{pos(i)}.T1(1,4) =  -PSI(i);
0102                 r{pos(i)}.T2(1,4) =  +PSI(i);
0103                 r{pos(i)}.T1(1,3) =  +r{pos(i)}.Length/2*sin(PSI(i));
0104                 r{pos(i)}.T2(1,3) =  +r{pos(i)}.Length/2*sin(PSI(i));
0105                 r{pos(i)}.RotAboutX =   PSI(i);
0106          %       r{pos(i)}.Yaw =   PSI(i);
0107                 %DS =+L/2(1-cos(psi) both in and out, ignored. (if including, do not change sign!)
0108             end
0109         end
0110     case 's'
0111          
0112         % assign tilt field for easy recovery of the set error values
0113         %r(pos)=cellfun(@(el,rot)setfield(el,'Tilt',rot),r(pos),num2cell(PSI),'un',0);
0114         
0115         r=atsettiltdipole(r,pos,PSI);
0116     otherwise
0117         disp('tilt about x, y or s');
0118 end
0119 
0120 re=r;

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