Home > pubtools > local_lattice_params > machine_at.m

machine_at

PURPOSE ^

Machine AT will return the optics of the lattice. Essentially takes what

SYNOPSIS ^

function varargout = machine_at(varargin)

DESCRIPTION ^

 Machine AT will return the optics of the lattice. Essentially takes what
 twissring returns and restructures it so that its easier to use.

 optics = MACHINE_AT([THERING, DP, ELEMENTS, SPECIFIC_OPTICS])
 optics = MACHINE_AT(SPECIFIC_OPTICS)

 Defaults to loading THERING from global, DP = 0, uses all elements and
 calculates the dispersion.
 SPECIFIC_OPTICS is a string that defines which particular element to
 return. Eg. if SPECIFIC_OPTICS = 'betax', then MACHINE_AT will only
 return those numbers.

 Other options are 'file' which will allow one to export the optical
 functions to an xls spreadsheet and 'line' to specify if the THERING used
 is actually a transfer line. If using the transfer line then the user
 must also provide the initial conditions as specified by TWISSLINE.

 Added export of element names as well 14/11/06
 Added export to xls option. 12/05/05
 Eugene 28/05/04

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = machine_at(varargin)
0002 
0003 % Machine AT will return the optics of the lattice. Essentially takes what
0004 % twissring returns and restructures it so that its easier to use.
0005 %
0006 % optics = MACHINE_AT([THERING, DP, ELEMENTS, SPECIFIC_OPTICS])
0007 % optics = MACHINE_AT(SPECIFIC_OPTICS)
0008 %
0009 % Defaults to loading THERING from global, DP = 0, uses all elements and
0010 % calculates the dispersion.
0011 % SPECIFIC_OPTICS is a string that defines which particular element to
0012 % return. Eg. if SPECIFIC_OPTICS = 'betax', then MACHINE_AT will only
0013 % return those numbers.
0014 %
0015 % Other options are 'file' which will allow one to export the optical
0016 % functions to an xls spreadsheet and 'line' to specify if the THERING used
0017 % is actually a transfer line. If using the transfer line then the user
0018 % must also provide the initial conditions as specified by TWISSLINE.
0019 %
0020 % Added export of element names as well 14/11/06
0021 % Added export to xls option. 12/05/05
0022 % Eugene 28/05/04
0023 
0024 nspec_opt = 0;
0025 exportfile = 0;
0026 transferline = 0;
0027 tdin = [];
0028 for i=1:nargin
0029     if ischar(varargin{i}) && strcmpi(varargin{i},'file')
0030         exportfile = 1;
0031     elseif ischar(varargin{i}) && strcmpi(varargin{i},'line')
0032         transferline = 1;
0033     elseif isstruct(varargin{i})
0034         % Of all inputs there is only one struct type and that is for
0035         % twissline.
0036         tdin = varargin{i};
0037     else
0038         if isstr(varargin{i})
0039             nspec_opt = nspec_opt + 1;
0040             spec_opt{nspec_opt} = varargin{i};
0041         end
0042     end
0043 end
0044         
0045 args = 0;
0046 args = args + 1;
0047 if nargin >= args && ~isstr(varargin{args}) && ~isstruct(varargin{args})
0048     line_ring = varargin{args};
0049 else
0050     global THERING
0051     line_ring = THERING;
0052 end
0053 
0054 args = args + 1;
0055 if nargin >= args && ~isstr(varargin{args}) && ~isstruct(varargin{args})
0056     dp = varargin{args};
0057 else
0058     dp = 0;
0059 end
0060 
0061 args = args + 1;
0062 if nargin >= args && ~isstr(varargin{args}) && ~isstruct(varargin{args})
0063     elements = varargin{args};
0064 else
0065     elements = 1:length(line_ring)+1;
0066 end
0067 
0068 % Check that input struct supplied of 'line' is used
0069 if transferline
0070     if isempty(tdin)
0071         error('User must provide the twiss data input structure');
0072     end
0073     TD = twissline(line_ring, dp, tdin, elements, 'chrom', 1e-6);
0074 else
0075     TD = twissring(line_ring, dp, elements, 'chrom', 1e-6);
0076 end
0077 
0078 % Group element names into a cell array
0079 for i=1:length(elements)
0080     % Circular indexing
0081     iind = mod(elements(i)-1,length(line_ring))+1;
0082     elemnames{i,1} = line_ring{iind}.FamName;
0083     if isfield(line_ring{iind},'Length')
0084         elemLeff(i,1) = line_ring{iind}.Length;
0085     else
0086         elemLeff(i,1) = 0;
0087     end
0088 end
0089 optics.elemnames = elemnames;
0090 optics.elemLeff = elemLeff;
0091 
0092 temp = cat(1, TD.beta);
0093 optics.betax = temp(:,1);
0094 optics.betay = temp(:,2);
0095 
0096 temp = cat(1, TD.alpha);
0097 optics.alphax = temp(:,1);
0098 optics.alphay = temp(:,2);
0099 
0100 temp = cat(2, TD.Dispersion);
0101 optics.etax = temp(1,:)';
0102 optics.etapx = temp(2,:)';
0103 optics.etay = temp(3,:)';
0104 optics.etapy = temp(4,:)';
0105 
0106 temp = cat(2, TD.ClosedOrbit);
0107 optics.x = temp(1,:)';
0108 optics.px = temp(2,:)';
0109 optics.y = temp(3,:)';
0110 optics.py = temp(4,:)';
0111 
0112 temp = cat(1,TD.mu);
0113 optics.nux = temp(:,1)/(2*pi);
0114 optics.nuy = temp(:,2)/(2*pi);
0115 
0116 optics.spos = cat(1,TD.SPos);
0117 
0118 if nspec_opt >= 1
0119     varargout{1} = optics.(spec_opt{1});
0120 else
0121     varargout{1} = optics;
0122 end
0123 
0124 if exportfile
0125     [filename pathname] = uiputfile('*.xls','Excel spreadsheet');
0126     entrystr = fieldnames(optics);
0127     temp = optics.(entrystr{1});
0128     for i=2:length(entrystr)
0129         temp = cat(2,temp,optics.(entrystr{i}));
0130     end
0131     xlswrite([pathname filename],entrystr','opticalparam','A1');
0132     xlswrite([pathname filename],temp,'opticalparam','A2');
0133 end

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