0001 function varargout = machine_at(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
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
0035
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
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
0079 for i=1:length(elements)
0080
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